Skip to main content

Official Python SDK for LlamaGen Comic API and Animation API

Project description

llamagen-python

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

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

Install

pip install llamagen-python

Quick Start

import os
from llamagen import LlamaGenClient

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

created = llamagen.comic.create({
    "prompt": "A 4-panel comic about Leo finding a glowing key in a quiet library.",
    "style": "manga",
    "fixPanelNum": 4,
})

done = llamagen.comic.wait_for_completion(created["id"])
print(done["status"], done.get("comics"))

Client

llamagen = LlamaGenClient(
    api_key="YOUR_API_KEY",
    base_url="https://api.llamagen.ai/v1",
    timeout_ms=30000,
    max_retries=2,
    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.

generation = llamagen.comic.create({
    "prompt": "The Little Prince meets the Fox in a luminous desert.",
    "style": "storybook manga",
    "size": "1024x1024",
    "pagination": {"totalPages": 2, "panelsPerPage": 4},
    "comicRoles": [
        {
            "name": "The Little Prince",
            "image": "https://example.com/prince.png",
            "clothing": "green coat and yellow scarf",
        }
    ],
    "attachments": [{"type": "image", "url": "https://example.com/reference.png"}],
    "language": "en",
    "upscale": "2K",
})

Comic methods:

  • llamagen.comic.create(params) calls POST /v1/comics/generations.
  • llamagen.comic.get(id, page=None, panel=None) calls GET /v1/comics/generations/{id}.
  • llamagen.comic.continue_write(id, params) extends an existing comic.
  • llamagen.comic.update_panel(id, params) regenerates one panel.
  • llamagen.comic.usage() calls GET /v1/comics/usage.
  • 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.
  • llamagen.comic.create_batch(params_list, concurrency=3) submits many jobs.
  • llamagen.comic.wait_for_many(ids, concurrency=3) polls many jobs.

JavaScript-style aliases are also available: createComic, getComic, continueComic, regeneratePanel, updateComicPanel, waitForCompletion, createAndWait, and waitForMany.

Animation API

video = llamagen.animation.create({
    "prompt": "A heroic fox detective walks through neon rain, cinematic camera move.",
    "videoOptions": {
        "duration": 5,
        "resolution": "720p",
        "aspect_ratio": "16:9",
        "image": "https://example.com/first-frame.png",
        "last_frame_image": "https://example.com/last-frame.png",
        "reference_images": ["https://example.com/character.png"],
    },
})

finished = llamagen.animation.wait_for_completion(
    video["id"],
    interval_ms=5000,
    timeout_ms=300000,
)

Animation methods:

  • llamagen.animation.create(params) calls POST /v1/artworks/generations.
  • llamagen.animation.get(id) calls GET /v1/artworks/generations/{id}.
  • llamagen.animation.wait_for_completion(id, **options) polls video status.
  • llamagen.animation.create_and_wait(params, **options) creates and polls.

llamagen.animations is an alias for llamagen.animation.

Webhooks

from llamagen import construct_webhook_event

event = construct_webhook_event(
    payload=raw_body,
    headers=request_headers,
    secret=os.environ["LLAMAGEN_WEBHOOK_SECRET"],
)

The helper verifies X-Llama-Webhook-Timestamp and X-Llama-Webhook-Signature with HMAC SHA-256 and a default 5-minute tolerance.

Errors

from llamagen import LlamaGenAPIError, LlamaGenConnectionError, LlamaGenTimeoutError

try:
    usage = llamagen.comic.usage()
except LlamaGenAPIError as error:
    print(error.status, 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.

Publishing

Maintainers can follow the release guide in docs/RELEASE.md.

Local Dev

python -m unittest discover -s tests
python -m compileall src tests

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.2.tar.gz (17.7 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.2-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llamagen_python-0.1.2.tar.gz
  • Upload date:
  • Size: 17.7 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.2.tar.gz
Algorithm Hash digest
SHA256 4beff18a2f1dfd017766880d6e61d1551172c3de6b9892f6c08c5b70b61e121c
MD5 8f753b7a721af7c65ce5aed16f41613f
BLAKE2b-256 505e33569c4126de9f86492b76d6be6d00b6f24caee51d7c360678270a15d8aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llamagen_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eba89d7c814ee398fc97e360ddbd512428309e981e33c21c164e4f2c6836e7b7
MD5 042284f5aebba6ba3610b95684e79d4c
BLAKE2b-256 ec504f24a36c174310ba0b8fca24c99d6c2185ec62d4edc66a19185b8ed81a9b

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