Skip to main content

Official Python SDK for LlamaGen Comic API and Animation API

Project description

LlamaGen Python SDK

Official Python SDK for LlamaGen's Comic API and Animation API.

Homepage: https://llamagen.ai/comic-api

Install

pip install llamagen-python

Get Your API Key

  1. Open the LlamaGen Comic API Dashboard.
  2. Sign in and create an API key.
  3. Use the key with the SDK or an HTTP Authorization header:
Authorization: Bearer YOUR_API_KEY

For local SDK examples, set the key in your shell or in a local .env file:

LLAMAGEN_API_KEY=YOUR_API_KEY

Quick Start

This example creates one comic generation and waits for the final result. API generation calls consume credits.

import os

from llamagen import LlamaGenClient

WAIT_TIMEOUT_MS = 30 * 60 * 1000

client = LlamaGenClient(
    api_key=os.environ["LLAMAGEN_API_KEY"],
    timeout_ms=30000,
    max_retries=5,
    retry_delay_ms=500,
)

created = client.comic.create({
    "prompt": "A 4-panel comic about Leo finding a glowing key in a quiet library.",
    "preset": "japanese_manga",
    "fixPanelNum": 4,
})
print("comic.create:", created["id"], created.get("status"))

done = client.comic.wait_for_completion(created["id"], timeout_ms=WAIT_TIMEOUT_MS)
print("comic.wait_for_completion:", done["id"], done.get("status"), done.get("comics"))

All Python examples below are self-contained for copy/paste usage in your own script, notebook, worker, or backend service. Replace YOUR_COMIC_ID or YOUR_ANIMATION_ID with an existing generation ID when an example fetches, waits for, continues, or updates an existing job.

Configure The Client

from llamagen import LlamaGenClient

client = LlamaGenClient(
    api_key="YOUR_API_KEY",
    base_url="https://api.llamagen.ai/v1",
    timeout_ms=30000,
    max_retries=5,
    retry_delay_ms=500,
)

The SDK uses Python's standard library HTTP stack and does not require runtime dependencies.

Comic API

Use llamagen.comic to create comics, manga, webtoons, storyboards, consistent-character pages, and panel edits.

Create with advanced options:

import os

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

generation = client.comic.create({
    "prompt": "The Little Prince meets the Fox in a luminous desert.",
    "preset": "animeStyle",
    "size": "1024x1024",
    "pagination": {"totalPages": 2, "panelsPerPage": 4},
    "comicRoles": [
        {
            "name": "The Little Prince",
            "image": "https://s.llamagen.ai/public/61965b97-23fe-4405-853d-efe17b5d6f08-prince.webp",
            "dress": "green coat and yellow scarf",
        }
    ],
    "attachments": [
        {
            "type": "image",
            "url": "https://s.llamagen.ai/public/7eeaad2c-fd6b-4679-90ce-884503f011b7-reference.webp",
        }
    ],
    "language": "en",
    "upscale": "2K",
})

Comic methods:

  • llamagen.comic.create(params) submits a new comic generation job and returns the created job id, status, and usage metadata. Use preset for a known style preset id; keep prompt focused on story, characters, scene, and action.
  • llamagen.comic.get(id, page=None, panel=None) fetches a comic generation's status and result, or a specific page or panel.
  • llamagen.comic.continue_write(id, params) extends an existing comic.
  • llamagen.comic.update_panel(id, params) regenerates one panel.
  • llamagen.comic.usage() fetches the current Comic API usage, available quota, and credit information for the API key.
  • llamagen.comic.upload(file, filename=None) calls POST /v1/comics/upload.
  • llamagen.comic.wait_for_completion(id, **options) polls until a terminal status.
  • llamagen.comic.create_and_wait(params, **options) creates and polls.

Comic examples:

Create a comic generation:

import os

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

created = client.comic.create({
    "prompt": "A 4-panel comic about Leo finding a glowing key in a quiet library.",
    "preset": "comicBookStyle",
    "fixPanelNum": 4,
})
print("comic.create:", created["id"], created.get("status"))

Fetch a comic generation, page, or panel:

import os

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
comic_id = "YOUR_COMIC_ID"

fetched = client.comic.get(comic_id)
print("comic.get:", fetched["id"], fetched.get("status"))

panel = client.comic.get(comic_id, page=0, panel=0)
print("comic.get panel:", panel.get("id", comic_id), panel.get("status"))

Wait for completion. The default timeout is 30 minutes:

import os

from llamagen import LlamaGenClient

WAIT_TIMEOUT_MS = 30 * 60 * 1000

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
comic_id = "YOUR_COMIC_ID"

done = client.comic.wait_for_completion(comic_id, timeout_ms=WAIT_TIMEOUT_MS)
print("comic.wait_for_completion:", done["id"], done.get("status"), done.get("comics"))

Create and wait in one call:

import os

from llamagen import LlamaGenClient

WAIT_TIMEOUT_MS = 30 * 60 * 1000

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

finished = client.comic.create_and_wait({
    "prompt": "A cozy 3-panel comic about a robot learning to bake bread.",
    "preset": "comicBookStyle",
    "fixPanelNum": 3,
}, timeout_ms=WAIT_TIMEOUT_MS)
print("comic.create_and_wait:", finished["id"], finished.get("status"))

Continue an existing comic:

import os

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
comic_id = "YOUR_COMIC_ID"

continued = client.comic.continue_write(
    comic_id,
    {
        "prompt": "Continue the story with Leo opening a secret reading room.",
        "pagination": {"totalPages": 1, "panelsPerPage": 4},
    },
)
print("comic.continue_write:", continued["id"], continued.get("status"))

Regenerate one panel:

import os

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
comic_id = "YOUR_COMIC_ID"

updated = client.comic.update_panel(
    comic_id,
    {
        "panelIndex": 0,
        "prompt": "Make the glowing key brighter and add dramatic moonlight.",
    },
)
print("comic.update_panel:", updated["id"], updated.get("status"))

Check usage:

import os

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

usage = client.comic.usage()
print("comic.usage:", usage)

Upload a local reference image:

import os
from pathlib import Path

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

image_path = Path("reference.png")
uploaded = client.comic.upload(image_path)
print("comic.upload:", uploaded)

Animation API

Create an animation job and wait for completion:

import os

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

video = client.animation.create({
    "prompt": "A heroic fox detective walks through neon rain, cinematic camera move.",
    "videoOptions": {
        "duration": 5,
        "resolution": "720p",
        "aspect_ratio": "16:9",
    },
})
print("animation.create:", video["id"], video.get("status"))

finished = client.animation.wait_for_completion(
    video["id"],
    interval_ms=5000,
    timeout_ms=30 * 60 * 1000,
)
print("animation.wait_for_completion:", finished["id"], finished.get("status"))

Animation methods:

  • llamagen.animation.create(params) submits a new animation generation job and returns the created job id, status, and usage metadata.
  • llamagen.animation.get(id) fetches an animation generation's status, result, and output video metadata.
  • llamagen.animation.wait_for_completion(id, **options) polls video status.
  • llamagen.animation.create_and_wait(params, **options) creates and polls.

Animation examples:

Create an animation job:

import os

from llamagen import LlamaGenClient

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

video = client.animation.create({
    "prompt": "A heroic fox detective walks through neon rain, cinematic camera move.",
    "videoOptions": {
        "duration": 5,
        "resolution": "720p",
        "aspect_ratio": "16:9",
    },
})
print("animation.create:", video["id"], video.get("status"))

Fetch and wait for an animation:

import os

from llamagen import LlamaGenClient

WAIT_TIMEOUT_MS = 30 * 60 * 1000

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])
animation_id = "YOUR_ANIMATION_ID"

fetched = client.animation.get(animation_id)
print("animation.get:", fetched["id"], fetched.get("status"))

finished = client.animation.wait_for_completion(animation_id, timeout_ms=WAIT_TIMEOUT_MS)
print("animation.wait_for_completion:", finished["id"], finished.get("status"))

Create and wait for an animation in one call:

import os

from llamagen import LlamaGenClient

WAIT_TIMEOUT_MS = 30 * 60 * 1000

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

finished = client.animation.create_and_wait({
    "prompt": "A paper boat sailing across a watercolor city at sunrise.",
    "videoOptions": {
        "duration": 5,
        "resolution": "720p",
        "aspect_ratio": "16:9",
    },
}, timeout_ms=WAIT_TIMEOUT_MS)
print("animation.create_and_wait:", finished["id"], finished.get("status"))

Error Handling

API errors include the HTTP status, parsed server response, and a readable message. For example, a 429 response can include an error code and message such as insufficient credits.

import os

from llamagen import (
    LlamaGenAPIError,
    LlamaGenClient,
    LlamaGenConnectionError,
    LlamaGenTimeoutError,
)

client = LlamaGenClient(api_key=os.environ["LLAMAGEN_API_KEY"])

try:
    usage = client.comic.usage()
except LlamaGenAPIError as error:
    print("API request failed:", error)
    print("HTTP status:", error.status)
    print("Server response:", error.data)
except LlamaGenConnectionError as error:
    print("Network connection failed:", error)
except LlamaGenTimeoutError as error:
    print("Request timed out:", error)
  • LlamaGenAPIError: the API returned a non-2xx response, such as 401, 403, or 429.
  • LlamaGenConnectionError: the SDK could not connect to the API after retries.
  • LlamaGenTimeoutError: the request timed out after retries.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llamagen_python-0.1.13.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llamagen_python-0.1.13-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file llamagen_python-0.1.13.tar.gz.

File metadata

  • Download URL: llamagen_python-0.1.13.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for llamagen_python-0.1.13.tar.gz
Algorithm Hash digest
SHA256 84250bc3068e511701574ec4350a1a84f0105dbca3ee65fd759da40e45dc8d83
MD5 2e09efe0a059c481ff8543e547605de3
BLAKE2b-256 265970c77a3724bfc69b926b97f52c228b8eaa1fa54a57fc1dd8898f1470897a

See more details on using hashes here.

File details

Details for the file llamagen_python-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for llamagen_python-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 d1430a10424219ed734af055b56c500e1c36e03cf3628fe0cb9f39e7e848b470
MD5 64894c3353c9e0c8d8f7ad3dd8e25d00
BLAKE2b-256 f491936d4c44dd18231d9e568dfec8bf3dac750f29cea194150989347c346bb3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page