Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Generate images, videos, audio, transcriptions, embeddings, and more — all thr
- **Model-card defaults** — `width`, `height`, `steps`, `fps`, `seed`, ... are optional; the SDK fills them from the model card
- **Type-safe** — full type hints, Pydantic v2 models, `py.typed` marker
- **Webhook verification** — HMAC-SHA256 signature validation utility
- **File flexibility** — accepts file paths, `Path` objects, bytes, or file-like objects
- **File flexibility** — accepts `Path` objects, bytes, or binary file objects (never a bare `str` path)

## Installation

Expand All @@ -51,7 +51,7 @@ For development (`pytest` runs from the repo root):
git clone https://github.com/deapi-ai/deapi-python-sdk.git
cd deapi-python-sdk
pip install -e ".[dev]"
pytest
pytest # unit tests only; `pytest -m integration` runs paid tests against production
```

## API keys
Expand Down Expand Up @@ -107,6 +107,7 @@ client = DeapiClient(
| `app_key` (`client.realtime()`) | `DEAPI_WS_APP_KEY` | public app key |
| `timeout` | — | `30.0` |
| `max_retries` | — | `3` |
| `max_retry_after` | — | `60.0` (cap on a 429 `Retry-After` sleep, in seconds) |

```python
client = DeapiClient() # reads the environment
Expand All @@ -130,6 +131,8 @@ Disable with `DeapiClient(fill_model_defaults=False)` or `DEAPI_FILL_MODEL_DEFAU
### Image Generation

```python
from pathlib import Path

# Text-to-image
job = client.images.generate(
prompt="mountain landscape at sunset",
Expand All @@ -149,46 +152,48 @@ print(result.results_alt_formats) # {"jpg": "...", "webp": "..."}
# Image edits: image= for one source, images=[...] for several (not both)
job = client.images.transform(
prompt="make it look like a watercolor painting",
image="photo.jpg", # path, Path, bytes or file-like
image=Path("photo.jpg"), # Path, bytes or a binary file object (not a plain str)
model="QwenImageEdit_Plus_NF4",
)

job = client.images.upscale(image="low_res.png", model="RealESRGAN_x4")
job = client.images.remove_background(image="photo.png", model="Ben2")
job = client.images.upscale(image=Path("low_res.png"), model="RealESRGAN_x4")
job = client.images.remove_background(image=Path("photo.png"), model="Ben2")
```

### Video Generation

```python
from pathlib import Path

# Text-to-video
job = client.video.generate(
prompt="a rocket launching into space",
model="Ltx2_19B_Dist_FP8",
model="Ltx2_5_22B_Dist_INT8",
width=768, height=512, frames=120, fps=24,
)

# Image-to-video with keyframes
job = client.video.animate(
prompt="gentle camera pan across the scene",
first_frame_image="landscape.jpg",
model="Ltx2_19B_Dist_FP8",
first_frame_image=Path("landscape.jpg"),
model="Ltx2_5_22B_Dist_INT8",
)

# Reference mode: list order binds files to <Picture N> / <Video N> / <Audio N> in the prompt.
# Mutually exclusive with first/last frame images.
job = client.video.animate(
prompt="<Picture 1> walks through the scene from <Video 1>, speaking <Audio 1>",
model="<model-with-reference-support>",
ref_images=["character.png"],
ref_videos=["scene.mp4"],
ref_audios=["voice.mp3"],
model="MiniMaxH3_33B_Turbo_INT8", # a model whose card has supports_*_refs
ref_images=[Path("character.png")],
ref_videos=[Path("scene.mp4")],
ref_audios=[Path("voice.mp3")],
)

# Audio-to-video
job = client.video.generate_from_audio(
prompt="visualize the music with abstract shapes",
audio="track.mp3",
model="ltx-audio2video",
audio=Path("track.mp3"),
model="Ltx2_5_22B_Dist_INT8",
)

# Describe a video: events, scenes and metadata
Expand All @@ -206,6 +211,8 @@ the API never accepts more than 9 images, 1 video or 3 audios.
### Audio

```python
from pathlib import Path

# Text-to-speech
job = client.audio.synthesize(
text="Hello, welcome to DeAPI!",
Expand All @@ -218,17 +225,19 @@ job = client.audio.synthesize(
# Text-to-music, optionally with a style reference clip
job = client.audio.compose(
caption="upbeat electronic track with synth leads",
model="MusicGen",
model="AceStep_1_5_XL_Turbo_INT8",
duration=30,
reference_audio="style.mp3",
reference_audio=Path("style.mp3"),
)
```

### Transcription

```python
from pathlib import Path

job = client.transcription.create(
source_url="https://youtube.com/watch?v=dQw4w9WgXcQ", # or source_file="interview.mp3"
source_url="https://youtube.com/watch?v=dQw4w9WgXcQ", # or source_file=Path("interview.mp3")
model="WhisperLargeV3Ct2",
ts_level="segment", # segment | word | char (implies include_ts)
diarize=True, # label speakers (implies timestamps)
Expand All @@ -251,13 +260,15 @@ return plain text with timestamps inline. `client.transcription.get_transcript(r
### Embeddings and OCR

```python
from pathlib import Path

job = client.embeddings.create(
input=["first sentence", "second sentence"], # or a single string
model="Bge_M3_FP16",
return_result_in_response=True,
)

job = client.ocr.extract(image="scan.png", model="<ocr-model>", return_result_in_response=True)
job = client.ocr.extract(image=Path("scan.png"), model="Nanonets_Ocr_S_F16", return_result_in_response=True)
```

### Prompt Enhancement
Expand Down
12 changes: 8 additions & 4 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ client = DeapiClient(
max_retries: int | None = None, # Retry attempts (default 3), see "Retry policy"
api_version: str | None = None, # Falls back to DEAPI_API_VERSION (only "v2" is accepted, default)
fill_model_defaults: bool | None = None, # Falls back to DEAPI_FILL_MODEL_DEFAULTS (default on)
max_retry_after: float | None = None, # Cap on a 429 Retry-After sleep in seconds (default 60.0)
http_client: httpx.Client | None = None, # Share one httpx client (connection pool) across SDK clients
owns_http_client: bool | None = None, # Close the injected http_client on close() (default: no)
)
```

Expand Down Expand Up @@ -89,7 +92,8 @@ Explicit values always win. Disable with `DeapiClient(fill_model_defaults=False)

## Conventions

- `FileInput` is `str` (path), `Path`, `bytes` or a binary file-like object.
- `FileInput` is `Path`, `bytes` or a binary file object. A plain `str` is rejected (wrap a path in
`Path(...)`), so untrusted input can never make the SDK read a local file.
- Every job method returns a `Job` and has a `*_price` counterpart returning `PriceResult`. Price
methods take the same model parameters (not `webhook_*`). The `enhance_prompt` fee is billed on
the job and is **not** included in a price quote.
Expand Down Expand Up @@ -327,7 +331,7 @@ present, else downloads `result_url` without the API key.
client.video.upscale(*, video: FileInput, model: str, webhook_url=None, webhook_secret=None) -> Job
```

`upscale_price()` takes `model` plus `video` **or** `width` + `height` + `duration` (seconds). `upscale()` takes `scale` (2 or 4) on models whose card has a `scale` range, e.g. FlashVSR_Tiny.
`upscale_price()` takes `model` plus `video` **or** `width` + `height` + `duration` (seconds). `upscale()` takes `scale` on models whose card has a `scale` range (FlashVSR_Tiny: 2-4).

Video character replacement and video background removal were removed in 0.5.0; use `animate()`
with the character as `ref_images` and the source motion as `ref_videos` to replace a character.
Expand Down Expand Up @@ -459,7 +463,7 @@ parameters.
```python
response = client.models.list(
*,
limit: int | None = None, # page size (default 50, server cap 100)
limit: int | None = None, # page size (default 50, server cap 50)
page: int = 1,
inference_types: list[str] | None = None, # e.g. ["txt2img", "img2img"]
tags: list[str] | None = None, # e.g. ["new", "beta"]
Expand Down Expand Up @@ -603,7 +607,7 @@ function) and `async for event in rt.events()`.

- WebSocket events drive progress and completion. On `done` the SDK fetches the final `JobResult`
over HTTP (fresh signed `result_url`, all fields).
- Failed jobs are **not** announced over WebSocket. `wait()` checks the job status over HTTP right
- Failed jobs are **usually not** announced over WebSocket. `wait()` checks the job status over HTTP right
away, every `poll_interval` seconds, and right after every reconnect. A failed job is returned
with `status == "error"`, exactly like `Job.wait()`; it is not raised.
- Open the connection **before** submitting jobs so no event is missed. A job that finished earlier
Expand Down
8 changes: 5 additions & 3 deletions examples/basic_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
python examples/basic_image.py
"""

from pathlib import Path # noqa: F401 - used by the commented-out examples below

from deapi_sdk import DeapiClient

client = DeapiClient()
Expand Down Expand Up @@ -48,7 +50,7 @@
# print("\nTransforming image...")
# job = client.images.transform(
# prompt="make it look like a watercolor painting",
# image="photo.jpg", # accepts str path, Path, bytes, or file-like
# image=Path("photo.jpg"), # Path, bytes or a binary file object (a plain str is rejected)
# model="QwenImageEdit_Plus_NF4",
# steps=30,
# seed=42,
Expand All @@ -61,7 +63,7 @@
# Uncomment to run — requires an image file:
#
# print("\nUpscaling image...")
# job = client.images.upscale(image="low_res.png", model="RealESRGAN_x4")
# job = client.images.upscale(image=Path("low_res.png"), model="RealESRGAN_x4")
# result = job.wait()
# print(f"Upscaled: {result.result_url}")

Expand All @@ -70,7 +72,7 @@
# Uncomment to run — requires an image file:
#
# print("\nRemoving background...")
# job = client.images.remove_background(image="photo.png", model="Ben2")
# job = client.images.remove_background(image=Path("photo.png"), model="Ben2")
# result = job.wait()
# print(f"Background removed: {result.result_url}")

Expand Down
4 changes: 3 additions & 1 deletion examples/transcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
python examples/transcription.py
"""

from pathlib import Path # noqa: F401 - used by the commented-out examples below

from deapi_sdk import DeapiClient

client = DeapiClient()
Expand Down Expand Up @@ -48,7 +50,7 @@ def show(model: str, **options) -> None:
#
# print("\nTranscribing audio file...")
# job = client.transcription.create(
# source_file="interview.mp3", # accepts str path, Path, bytes, or file-like
# source_file=Path("interview.mp3"), # Path, bytes or a binary file object (a plain str is rejected)
# include_ts=False,
# model="WhisperLargeV3",
# return_result_in_response=True,
Expand Down
23 changes: 12 additions & 11 deletions examples/tts_and_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
python examples/tts_and_audio.py
"""

from pathlib import Path # noqa: F401 - used by the commented-out examples below

from deapi_sdk import DeapiClient

client = DeapiClient()
Expand All @@ -28,18 +30,17 @@

# --- TTS with voice cloning ---

# Uncomment to run — requires a reference audio file (3-10 seconds):
# Uncomment to run — requires a reference audio file (5-15 seconds). Voice cloning needs a
# model whose card has supports_voice_clone (here Qwen3_TTS_12Hz_1_7B_Base; Kokoro does not clone).
#
# print("\nCloning voice...")
# job = client.audio.synthesize(
# text="This is generated using a cloned voice.",
# model="Kokoro",
# lang="en-us",
# format="wav",
# speed=1.0,
# sample_rate=24000,
# model="Qwen3_TTS_12Hz_1_7B_Base",
# lang="English",
# format="mp3",
# mode="voice_clone",
# ref_audio="voice_sample.wav", # 3-10 second reference clip
# ref_audio=Path("voice_sample.wav"), # 5-15 second reference clip
# ref_text="The original text spoken in the reference.",
# )
# result = job.wait()
Expand Down Expand Up @@ -75,10 +76,10 @@
# print("\nComposing music...")
# job = client.audio.compose(
# caption="upbeat electronic track with synth leads and a driving bassline",
# model="MusicGen",
# duration=30, # 30 seconds
# inference_steps=50,
# guidance_scale=3.0,
# model="AceStep_1_5_XL_Turbo_INT8",
# duration=30, # 30 seconds (10-300)
# inference_steps=8, # fixed for this model
# guidance_scale=1.0, # fixed for this model
# seed=42,
# format="mp3",
# lyrics="Dancing in the moonlight, feeling so alive",
Expand Down
35 changes: 16 additions & 19 deletions examples/video_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
python examples/video_generation.py
"""

from pathlib import Path # noqa: F401 - used by the commented-out examples below

from deapi_sdk import DeapiClient

client = DeapiClient()
Expand All @@ -16,11 +18,9 @@
print("Generating video from text...")
job = client.video.generate(
prompt="a rocket launching into space, cinematic, slow motion",
negative_prompt="blurry, low quality",
model="Ltx2_19B_Dist_FP8",
model="Ltx2_5_22B_Dist_INT8",
width=768,
height=512,
steps=1,
seed=42,
frames=120,
fps=24,
Expand All @@ -38,8 +38,8 @@
# print("\nAnimating image...")
# job = client.video.animate(
# prompt="gentle camera pan across the landscape with clouds moving",
# first_frame_image="landscape.jpg",
# model="Ltx2_19B_Dist_FP8",
# first_frame_image=Path("landscape.jpg"),
# model="Ltx2_5_22B_Dist_INT8",
# seed=42,
# width=768,
# height=512,
Expand All @@ -55,9 +55,9 @@
#
# job = client.video.animate(
# prompt="smooth transition from day to night",
# first_frame_image="daytime.jpg",
# last_frame_image="nighttime.jpg",
# model="Ltx2_19B_Dist_FP8",
# first_frame_image=Path("daytime.jpg"),
# last_frame_image=Path("nighttime.jpg"),
# model="Ltx2_5_22B_Dist_INT8",
# seed=42,
# width=768,
# height=512,
Expand All @@ -72,8 +72,8 @@
# print("\nGenerating video from audio...")
# job = client.video.generate_from_audio(
# prompt="abstract shapes pulsing to the beat",
# audio="track.mp3",
# model="ltx-audio2video",
# audio=Path("track.mp3"),
# model="Ltx2_5_22B_Dist_INT8",
# width=512,
# height=512,
# seed=42,
Expand All @@ -87,36 +87,33 @@
#
# job = client.video.generate_from_audio(
# prompt="music visualization",
# audio="track.mp3",
# first_frame_image="start_frame.png",
# last_frame_image="end_frame.png",
# model="ltx-audio2video",
# audio=Path("track.mp3"),
# first_frame_image=Path("start_frame.png"),
# last_frame_image=Path("end_frame.png"),
# model="Ltx2_5_22B_Dist_INT8",
# width=512,
# height=512,
# seed=42,
# frames=97,
# fps=24,
# guidance=7.5,
# steps=20,
# )

# --- Video upscale ---

# Uncomment to run — requires a video file:
#
# print("\nUpscaling video...")
# job = client.video.upscale(video=Path("low_res.mp4"), model="vid-upscale-model") # from pathlib import Path
# job = client.video.upscale(video=Path("low_res.mp4"), model="FlashVSR_Tiny", scale=2)
# result = job.wait()
# print(f"Upscaled: {result.result_url}")

# --- Price calculation ---

price = client.video.generate_price(
prompt="a rocket launching",
model="Ltx2_19B_Dist_FP8",
model="Ltx2_5_22B_Dist_INT8",
width=768,
height=512,
steps=1,
seed=42,
frames=120,
fps=24,
Expand Down
Loading