Python Quickstart
Prerequisites
Installation
pip install shortgeniuspip install --upgrade shortgeniusQuick Start
1
from shortgenius import Shortgenius
# Initialize with API key
client = Shortgenius(
api_key="YOUR_API_KEY" # or use os.environ.get("SHORTGENIUS_API_KEY")
)2
from shortgenius import Shortgenius
client = Shortgenius(api_key="YOUR_API_KEY")
# Check API health
status = client.health.check()
print(f"API Status: {status.status}") # Should print: API Status: ok3
# List available voices
voices = client.audio.voices.list_voices(locale="en-US")
print(f"Found {len(voices)} voices")
for voice in voices[:3]: # Show first 3 voices
print(f" - {voice.name} ({voice.source})")
if voice.tags:
print(f" Gender: {voice.tags.gender}, Accent: {voice.tags.accent}")
# Check your credits
credits = client.credits.list()
print(f"Credits: {credits.balance.credits}")4
# List available image styles
styles = client.images.list_styles()
print(f"Found {len(styles)} image styles")
# Show first few styles
for style in styles[:3]:
print(f" - {style.name}: {style.prompt}")
# Create an image
try:
image = client.images.create(
prompt="A serene mountain landscape at sunset",
aspect_ratio="9:16",
wait_for_generation=True
)
print(f"\nImage created: {image.id}")
print(f"URL: {image.url}")
except Exception as e:
print(f"Image creation failed: {e}")
print("This might be due to insufficient credits")5
# Get necessary resources
connections = client.connections.list()
voices = client.audio.voices.list_voices(locale="en-US")
if not connections:
print("Please set up a publishing connection first!")
exit()
# Generate video topics
topics = client.videos.generate_topics(
parent_topic="space exploration",
locale="en-US",
number_of_topics=3
)
print(f"Generated {len(topics)} video topics:")
for i, topic in enumerate(topics[:3], 1):
print(f" {i}. {topic}")
# Create a video with a topic
if topics:
video = client.videos.create(
topic=topics[0],
locale="en-US",
connection_ids=[connections[0].id],
voice_id=voices[0].id if voices else None,
aspect_ratio="9:16"
)
print(f"\nVideo created!")
print(f" ID: {video.id}")
print(f" Status: {video.publishing_state}")Complete Example
Error Handling
Async Support
Working with Different Content Types
Working with Images
Working with Audio
Working with Video Series
Configuration Options
Custom Timeout
Custom Base URL
Retry Configuration
Using Proxies
Working with Responses
Best Practices
Next Steps
Last updated