framera 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ dist/
6
+ build/
7
+ *.egg-info/
framera-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Framera AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
framera-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,532 @@
1
+ Metadata-Version: 2.5
2
+ Name: framera
3
+ Version: 1.0.0
4
+ Summary: Framera API for Python: AI films, avatar videos, UGC ads, images, audio, tools and swaps from your own app.
5
+ Project-URL: Homepage, https://developer.framera.ai
6
+ Project-URL: Documentation, https://developer.framera.ai/sdks
7
+ Project-URL: Repository, https://github.com/framera-ai/framera-python
8
+ Project-URL: Issues, https://github.com/framera-ai/framera-python/issues
9
+ Author: Framera AI
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai avatar,ai video,framera,image to video,sdk,text to video,ugc,video generation
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: httpx<1,>=0.23
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7; extra == 'dev'
28
+ Description-Content-Type: text/markdown
29
+
30
+ <p align="center">
31
+ <a href="https://developer.framera.ai"><img src="https://raw.githubusercontent.com/framera-ai/framera-python/main/.github/assets/framera-api-banner-python.jpg" alt="Framera AI: finished AI films from one API call" width="100%"></a>
32
+ </p>
33
+
34
+ <p align="center">
35
+ <a href="https://pypi.org/project/framera/"><img src="https://img.shields.io/pypi/v/framera?label=pypi&color=d2ff3c&labelColor=0b0b0c" alt="PyPI version"></a>
36
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-d2ff3c?labelColor=0b0b0c" alt="MIT licence"></a>
37
+ <a href="https://developer.framera.ai/docs"><img src="https://img.shields.io/badge/docs-developer.framera.ai-d2ff3c?labelColor=0b0b0c" alt="Docs"></a>
38
+ </p>
39
+
40
+ # Framera AI for Python
41
+
42
+ **Finished AI films from one API call.** Framera AI turns a prompt into a complete film of up to one minute, with scenes, dialogue, sound and music, in 720p or 1080p. Not a few seconds of raw clip: a finished film, ready to use.
43
+
44
+ **Highest quality, lowest price.** You pay per request from a prepaid balance, with no plans and no seats, and a request that fails is never charged. See every price at [developer.framera.ai/pricing](https://developer.framera.ai/pricing).
45
+
46
+ <p align="center">
47
+ <img src="https://raw.githubusercontent.com/framera-ai/framera-python/main/.github/assets/framera-api-products.jpg" alt="Everything you can make with the Framera AI API: films, picture to video, talking avatars, UGC ads, images, voice and audio, swap and image tools" width="100%">
48
+ </p>
49
+
50
+ | What you can make | What it does |
51
+ |---|---|
52
+ | **Films** | Up to a minute from one prompt, with dialogue, sound and music |
53
+ | **Picture to video** | Bring any image to life, with an optional last frame |
54
+ | **Talking avatars** | A photo and a script or voice, lips in sync |
55
+ | **UGC ads** | Product ads with the script written for you |
56
+ | **Images** | Leading image models in one call |
57
+ | **Voice and audio** | Text to speech, voice changer and translation |
58
+ | **Swap** | Put a person into any video clip |
59
+ | **Image tools** | Upscale, remove backgrounds and inpaint |
60
+
61
+ ```bash
62
+ pip install framera
63
+ ```
64
+
65
+ Python 3.9 or newer. One dependency: [httpx](https://www.python-httpx.org/). Sync (`Framera`) and asyncio (`AsyncFramera`) clients, fully typed.
66
+
67
+ ## Quick start
68
+
69
+ 1. Create an account at [developer.framera.ai](https://developer.framera.ai).
70
+ 2. Add credits to your balance.
71
+ 3. Create an API key (**Keys → Create key**).
72
+ 4. Make a request:
73
+
74
+ ```bash
75
+ export FRAMERA_API_KEY=fr_live_...
76
+ ```
77
+
78
+ ```python
79
+ from framera import Framera
80
+
81
+ client = Framera() # reads FRAMERA_API_KEY; or Framera(api_key="fr_live_...")
82
+
83
+ job = client.videos.create(
84
+ model="odyssey-1-ultra", # the default
85
+ prompt="A lighthouse keeper climbs the stairs at dusk, lights the lamp, and a ship turns towards the shore.",
86
+ duration_seconds=60,
87
+ resolution="720p",
88
+ aspect_ratio="16:9",
89
+ )
90
+
91
+ done = client.jobs.wait(job["id"])
92
+ if done["status"] == "succeeded":
93
+ print(done["outputs"][0]["url"], done["price"]["amount"])
94
+ else:
95
+ print(done["error"]["message"])
96
+ ```
97
+
98
+ Every create returns a **job** straight away. Wait for it with `jobs.wait`, or pass a `webhook_url` (or add a webhook endpoint) and we tell you when it is done.
99
+
100
+ ### Async
101
+
102
+ ```python
103
+ import asyncio
104
+ from framera import AsyncFramera
105
+
106
+ async def main() -> None:
107
+ async with AsyncFramera() as client:
108
+ job = await client.videos.create(prompt="…", duration_seconds=30)
109
+ done = await client.jobs.wait(job["id"])
110
+ print(done["status"])
111
+
112
+ asyncio.run(main())
113
+ ```
114
+
115
+ Everything below works the same on `AsyncFramera`: put `await` in front of the call, and use `async for` for lists.
116
+
117
+ ## Client options
118
+
119
+ ```python
120
+ Framera(
121
+ api_key="fr_live_...", # default: FRAMERA_API_KEY
122
+ base_url="https://api.framera.ai", # default (or FRAMERA_BASE_URL)
123
+ timeout=60.0, # seconds per request
124
+ max_retries=2, # on 429, 5xx and network errors
125
+ http_client=httpx.Client(proxy=...), # your own httpx client (httpx.AsyncClient for AsyncFramera)
126
+ )
127
+ ```
128
+
129
+ Use the client as a context manager (`with Framera() as client:`) or call `client.close()` / `await client.aclose()` when you are done.
130
+
131
+ ## Arguments and results
132
+
133
+ Keyword arguments are Python-style (`duration_seconds`, `aspect_ratio`, `webhook_url`); the SDK sends the API's JSON names (`durationSeconds`, …). Results are plain dicts with the API's own keys, typed as `TypedDict`s in `framera.types`, so `job["price"]["amount"]` and `job["createdAt"]` read exactly like the API reference.
134
+
135
+ Every create also takes:
136
+
137
+ - `webhook_url`: an https URL we POST the job's events to (signed with the account secret);
138
+ - `metadata`: up to 20 string values you get back on the job, e.g. `{"orderId": "42"}`;
139
+ - `idempotency_key`: see [Retries and idempotency](#retries-and-idempotency);
140
+ - `extra_body`: extra JSON fields to send as they are.
141
+
142
+ Wherever a request takes a file (`image`, `audio`, `video`, `mask`, references…) pass a public https URL or an `upload_…` id from `client.uploads.upload`.
143
+
144
+ ## Everything you can call
145
+
146
+ | Call | Endpoint |
147
+ | --- | --- |
148
+ | `models.list()` | `GET /v1/models`: every model by product, its settings and `pricing` |
149
+ | `quotes.create(product, operation=None, *, body=None, **params)` | `POST /v1/quotes`: the price of any request, without starting it |
150
+ | `quotes.video(...)`, `quotes.image(...)` | `POST /v1/quotes/video`, `/v1/quotes/image` (older shortcuts) |
151
+ | `videos.create(...)` | `POST /v1/videos`: text-to-video or image-to-video |
152
+ | `avatars.create(...)` | `POST /v1/avatars`: a photo that talks |
153
+ | `ugc.create(...)` | `POST /v1/ugc`: a UGC-style product ad, script included |
154
+ | `images.create(...)` | `POST /v1/images` |
155
+ | `tools.upscale(...)`, `tools.remove_background(...)`, `tools.inpaint(...)` | `POST /v1/tools/upscale`, `/remove-background`, `/inpaint` |
156
+ | `audio.speech(...)`, `audio.voice_change(...)`, `audio.translate(...)` | `POST /v1/audio/speech`, `/voice-change`, `/translate` |
157
+ | `swap.create(...)` | `POST /v1/swap`: put a person into a video |
158
+ | `uploads.create(...)`, `uploads.upload(file)` | `POST /v1/uploads` + the signed PUT |
159
+ | `jobs.get(id)`, `jobs.list(...)`, `jobs.wait(id)`, `jobs.cancel(id)` | `GET /v1/jobs/:id`, `GET /v1/jobs`, polling, `POST /v1/jobs/:id/cancel` |
160
+ | `balance.get()` | `GET /v1/balance` |
161
+ | `webhook_endpoints.create/list/get/update/delete/roll_secret` | `/v1/webhook-endpoints[/:id][/roll-secret]` |
162
+ | `events.list(...)`, `events.get(id)` | `GET /v1/events`, `GET /v1/events/:id` |
163
+ | `webhooks.secret()` | `GET /v1/webhook-secret`: the account secret for per-request `webhook_url` deliveries |
164
+ | `framera.webhooks.verify(body, header, secret)` | checks a webhook and returns the event |
165
+
166
+ ## The job object
167
+
168
+ All products return the same shape, with the settings you sent echoed on it:
169
+
170
+ ```python
171
+ {
172
+ "id": "3f6c2a8e-…", # a UUID
173
+ "object": "job",
174
+ "type": "video", # video | avatar | ugc | image | tool | audio | swap
175
+ "status": "queued", # queued | running | succeeded | failed | cancelled
176
+ "model": "odyssey-1-ultra",
177
+ "prompt": "…", "durationSeconds": 60, "resolution": "720p", "aspectRatio": "16:9", "sound": True,
178
+ "price": {"amount": 7.37, "currency": "usd"}, # example
179
+ "outputs": [{"type": "video", "url": "https://…", "expiresAt": "…"}],
180
+ "error": None, # {"code", "message"} when it failed or was cancelled
181
+ "metadata": {"orderId": "42"},
182
+ "createdAt": "…",
183
+ "completedAt": None,
184
+ }
185
+ ```
186
+
187
+ Some products add their own fields: tool and audio jobs have `operation` (`upscale`, `remove-background`, `inpaint`, `speech`, `voice-change`, `translate`); UGC jobs have `script`; translations have `transcript`, `translation` and `sourceLanguage`; avatars, voice changes, translations and swaps show the measured `durationSeconds`; upscale and inpaint show the picture's `width` and `height`.
188
+
189
+ `price` is fixed when the job is created, and charged only when it succeeds; a failed or cancelled job costs nothing. `outputs[i]["url"]` is a signed link valid for an hour (`expiresAt`). Save the file to your own storage, or call `jobs.get(id)` again for a fresh link.
190
+
191
+ ## Models and prices
192
+
193
+ ```python
194
+ models = client.models.list()
195
+ # {"object": "list", "video": [...], "avatar": [...], "ugc": [...], "image": [...], "tool": [...], "audio": [...], "swap": [...]}
196
+ print(models["video"][0]["pricing"]["perSecond"]) # price per second by resolution
197
+ for model in models["image"]:
198
+ print(model["id"], model["pricing"]["perImage"])
199
+ ```
200
+
201
+ Each model's `pricing` says how it is charged: `perSecond` (films and avatars, with `examples`), `perImage` (images and background removal), `byOutputMegapixels` (upscale), `perMegapixel` (inpaint), `per1000Characters` (speech), `perMinute` (voice changer, translation) or per-clip `examples` (swap, UGC). Read prices from here rather than hard-coding them.
202
+
203
+ Check what a request costs before you start it (a quote only looks up the price; it starts nothing). `quotes.create` takes the create's parameters plus `product`, and `operation` for tools and audio:
204
+
205
+ ```python
206
+ quote = client.quotes.create("video", prompt="A lighthouse at dusk", duration_seconds=60, resolution="720p")
207
+ # {"object": "quote", "product": "video", "model": "odyssey-1-ultra", "price": {"amount": 7.37, "currency": "usd"}}
208
+
209
+ client.quotes.create("image", model="nano-banana-pro", prompt="a poster", size="1k", count=2)
210
+ client.quotes.create("tool", "upscale", image="upload_…", factor=4)
211
+ client.quotes.create("audio", operation="speech", text="Hello there!")
212
+
213
+ # A UGC create has its own `product` field, so pass its body as `body`:
214
+ client.quotes.create("ugc", body={"product": {"name": "Cloud Mug", "images": ["upload_…"]}, "duration_seconds": 30})
215
+ ```
216
+
217
+ Either way the SDK sends `{"product", "operation"?, "body": {...createBody}}`; `body` works for every product.
218
+
219
+ To price a file before you have uploaded it, add its size: `duration_seconds` for an avatar from `audio`, a voice change, a translation or a swap, and `width` / `height` for an upscale or inpaint.
220
+
221
+ ## Videos
222
+
223
+ Odyssey 1 Ultra (`odyssey-1-ultra`, the default `model`) makes films from 5 to 60 seconds, in steps of 5.
224
+
225
+ ```python
226
+ # text to video
227
+ client.videos.create(
228
+ prompt="Two friends argue about the last slice of pizza on a rooftop at night.",
229
+ duration_seconds=60,
230
+ resolution="720p", # "480p", "720p" (default) or "1080p"
231
+ aspect_ratio="9:16", # "16:9" (default), "9:16", "1:1", "21:9", "4:3", "3:4"
232
+ sound=True, # dialogue, sound effects and music (default)
233
+ )
234
+
235
+ # a film from text with references: people, things and places to keep, clips and voices
236
+ client.videos.create(
237
+ prompt="Mia walks into the cafe and orders her usual.",
238
+ duration_seconds=30,
239
+ references={
240
+ "images": [{"image": "upload_…", "kind": "person", "name": "Mia"}, "https://example.com/cafe.jpg"], # up to 4
241
+ "clips": ["upload_…"], # up to 3
242
+ "voices": [{"audio": "upload_…", "name": "Mia"}], # up to 3
243
+ },
244
+ )
245
+
246
+ # image to video, with a closing picture (up to 15 s)
247
+ opening = client.uploads.upload("opening.png")
248
+ client.videos.create(
249
+ prompt="The camera pushes in as she turns and smiles.",
250
+ duration_seconds=10,
251
+ image=opening["id"],
252
+ end_image="https://example.com/closing.png",
253
+ )
254
+ ```
255
+
256
+ ## Avatars
257
+
258
+ A photo that talks: send `script` (read in `voice`), or your own `audio`.
259
+
260
+ ```python
261
+ client.avatars.create(
262
+ image="https://example.com/presenter.jpg",
263
+ script="Welcome to our spring collection.", # up to about 60 seconds of speech
264
+ voice="English_expressive_narrator", # the default; voices are in models.list()
265
+ language="en",
266
+ resolution="1080p", # "720p" (default) or "1080p"
267
+ music=True,
268
+ )
269
+
270
+ client.avatars.create(image="upload_…", audio="upload_…")
271
+ ```
272
+
273
+ The video keeps the photo's shape. Avatars are billed for at least 10 seconds.
274
+
275
+ ## UGC ads
276
+
277
+ Give us the product and a brief; we write the script (or use yours) and a presenter reads it. The job carries the `script`.
278
+
279
+ ```python
280
+ ad = client.ugc.create(
281
+ product={"name": "Cloud Mug", "description": "Keeps coffee hot all morning", "images": ["https://example.com/mug.jpg"]}, # 1 to 4 images
282
+ brief="Cosy morning routine, aimed at remote workers",
283
+ avatar="https://example.com/presenter.jpg", # with a presenter: a talking ad
284
+ duration_seconds=30, # 15 (default) or 30
285
+ aspect_ratio="9:16", # the default
286
+ resolution="720p", # or "1080p"
287
+ # script and voice are optional
288
+ )
289
+ print(ad["script"])
290
+ ```
291
+
292
+ Without `avatar`, the ad is a video made from your first product picture.
293
+
294
+ ## Images
295
+
296
+ ```python
297
+ client.images.create(
298
+ model="nano-banana-pro",
299
+ prompt="A neon-lit ramen bar in the rain",
300
+ size="2k", # "1k" (default), "2k" or "4k", as the model supports
301
+ aspect_ratio="16:9", # "1:1" (default), "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"
302
+ count=2, # 1 to 4
303
+ references=["https://example.com/style.jpg"],
304
+ )
305
+ ```
306
+
307
+ ## Tools
308
+
309
+ ```python
310
+ client.tools.upscale(image="upload_…", factor=4) # 2 (default) or 4
311
+ client.tools.remove_background(image="https://example.com/shoe.jpg")
312
+ client.tools.inpaint(image="upload_…", mask="upload_…", prompt="a red scarf", count=2)
313
+ ```
314
+
315
+ ## Audio
316
+
317
+ ```python
318
+ client.audio.speech(text="Hello there!", voice="English_expressive_narrator", language="en", emotion="happy", speed=1.1)
319
+ client.audio.voice_change(audio="upload_…", voice="Rachel") # a voice from the voice changer's list
320
+ client.audio.translate(video="upload_…", target_language="es") # or audio=..., voice=...
321
+ ```
322
+
323
+ A translation gives you the translated speech as audio, plus `transcript` and `translation` on the job.
324
+
325
+ ## Swap
326
+
327
+ ```python
328
+ client.swap.create(video="upload_…", image="https://example.com/person.jpg") # a clip of 3 to 14 seconds
329
+ ```
330
+
331
+ ## Uploads
332
+
333
+ `uploads.upload` reserves an upload, PUTs the bytes to the signed URL and returns the upload. Pass `upload["id"]` wherever a request takes a file.
334
+
335
+ ```python
336
+ up = client.uploads.upload("face.jpg") # a path (str or pathlib.Path)
337
+ up = client.uploads.upload(data, filename="voice.wav") # bytes
338
+ with open("clip.mp4", "rb") as fh:
339
+ up = client.uploads.upload(fh) # a binary file object
340
+ # content_type="..." overrides the type guessed from the file name
341
+ ```
342
+
343
+ Files: JPEG, PNG, WebP; MP3, WAV, M4A, AAC; MP4 and MOV. Up to 10 MB, videos up to 50 MB.
344
+
345
+ In two steps yourself (the PUT must carry exactly the `contentType` and `size` you reserved):
346
+
347
+ ```python
348
+ up = client.uploads.create(filename="clip.mp4", content_type="video/mp4", size=len(data))
349
+ # {"id": "upload_…", "object": "upload", "uploadUrl": ..., "expiresAt": ..., "contentType": "video/mp4", "size": ...}
350
+ httpx.put(up["uploadUrl"], content=data, headers={"Content-Type": up["contentType"], "Content-Length": str(up["size"])})
351
+ ```
352
+
353
+ ## Jobs
354
+
355
+ ```python
356
+ job = client.jobs.get("3f6c2a8e-…")
357
+
358
+ # one page (newest first)
359
+ page = client.jobs.list(limit=20, type="video", status="succeeded")
360
+ page.data, page.has_more # also page["data"], page["hasMore"]
361
+
362
+ # every job, page after page (starting_after is handled for you)
363
+ for job in client.jobs.list(type="avatar"):
364
+ print(job["id"], job["price"]["amount"])
365
+
366
+ for page in client.jobs.list(limit=50).iter_pages():
367
+ ...
368
+
369
+ # wait for one to finish
370
+ done = client.jobs.wait(
371
+ job["id"],
372
+ interval=5, # seconds between polls, at least 1
373
+ timeout=30 * 60, # default one hour, then WaitTimeoutError; None waits forever
374
+ on_update=lambda j: print(j["status"]),
375
+ )
376
+
377
+ # cancel while it is still queued; once it runs you get a JobNotCancellableError
378
+ client.jobs.cancel(job["id"])
379
+ ```
380
+
381
+ Async lists can be awaited for one page or walked with `async for`:
382
+
383
+ ```python
384
+ page = await client.jobs.list(limit=20)
385
+ async for job in client.jobs.list(status="failed"):
386
+ ...
387
+ ```
388
+
389
+ On `AsyncFramera`, `on_update` may be a plain function or a coroutine function.
390
+
391
+ ## Balance
392
+
393
+ ```python
394
+ balance = client.balance.get()
395
+ # {"object": "balance", "available": 42.5, "held": 7.37, "currency": "usd",
396
+ # "autoRecharge": {"enabled": True, "threshold": 10, "amount": 50}}
397
+ ```
398
+
399
+ `held` is money set aside for jobs that are still running. It is charged when a job succeeds and released when it fails or is cancelled. Top up and set auto-recharge in the console.
400
+
401
+ ## Webhooks
402
+
403
+ Films take minutes, so rather than waiting, let us call you. Add an endpoint once (with a key that has the `all` permission):
404
+
405
+ ```python
406
+ endpoint = client.webhook_endpoints.create(
407
+ url="https://your-app.com/framera-webhook",
408
+ events=["job.succeeded", "job.failed", "job.cancelled", "balance.low"], # default ["*"]: everything
409
+ description="Production",
410
+ )
411
+ print(endpoint["secret"]) # whsec_…: shown only now and when you roll it
412
+
413
+ client.webhook_endpoints.list()
414
+ client.webhook_endpoints.get(endpoint["id"])
415
+ client.webhook_endpoints.update(endpoint["id"], events=["*"], disabled=True) # description=None clears it
416
+ client.webhook_endpoints.roll_secret(endpoint["id"]) # a new secret; the old one stops working
417
+ client.webhook_endpoints.delete(endpoint["id"]) # {"id", "object": "webhook_endpoint", "deleted": True}
418
+ ```
419
+
420
+ Or pass `webhook_url` on a single create; those deliveries are signed with the account secret from `client.webhooks.secret()`.
421
+
422
+ Each delivery is an event. Event types: `job.succeeded`, `job.failed`, `job.cancelled`, `balance.low`, `balance.topped_up`, `balance.recharge_failed` (and `webhook.test` from the console).
423
+
424
+ ```json
425
+ { "id": "evt_…", "object": "event", "type": "job.succeeded", "createdAt": "…", "data": { "id": "…", "object": "job", "status": "succeeded", "outputs": [ … ] } }
426
+ ```
427
+
428
+ Verify it against the **raw** body. The `Framera-Signature` header is `t=<unix seconds>,v1=<hex HMAC-SHA256 of "t.body">`:
429
+
430
+ ```python
431
+ import os
432
+ import framera
433
+ from flask import Flask, request
434
+
435
+ app = Flask(__name__)
436
+
437
+ @app.post("/framera-webhook")
438
+ def framera_webhook():
439
+ try:
440
+ event = framera.webhooks.verify(
441
+ request.get_data(), # raw bytes, not re-serialised JSON
442
+ request.headers.get("Framera-Signature"),
443
+ os.environ["FRAMERA_WEBHOOK_SECRET"],
444
+ )
445
+ except framera.WebhookVerificationError:
446
+ return "", 400
447
+ if event["type"] == "job.succeeded":
448
+ save_video(event["data"]["metadata"]["orderId"], event["data"]["outputs"][0]["url"])
449
+ return "", 200
450
+ ```
451
+
452
+ Signatures more than 5 minutes old (or ahead) are refused; `tolerance=600` changes that. `framera.webhooks.sign(body, secret)` builds a header for testing your handler. Answer with any 2xx. When your endpoint is down or answers otherwise, we retry after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours.
453
+
454
+ ### Events
455
+
456
+ The same events are kept for you to read back:
457
+
458
+ ```python
459
+ latest = client.events.list(limit=10, type="job.failed")
460
+ for event in client.events.list():
461
+ print(event["type"])
462
+ event = client.events.get("evt_…")
463
+ ```
464
+
465
+ ## Errors
466
+
467
+ Every failed call raises a `framera.FrameraError` subclass with `status`, `code`, `message` and `details` (`None` when there are none):
468
+
469
+ | Class | Status | `code` | What to do |
470
+ | --- | --- | --- | --- |
471
+ | `InvalidRequestError` | 400 | `invalid_request` | Fix the request: `message` says what, `details["issues"]` lists the fields |
472
+ | `AuthenticationError` | 401 | `unauthorized` | Check the key (also raised as `missing_api_key` when none is set) |
473
+ | `InsufficientBalanceError` | 402 | `insufficient_balance` | Top up or turn on auto-recharge; `details` has `required` and `available` |
474
+ | `PermissionDeniedError` | 403 | `permission_denied` | `err.reason`: `key_permission`, `key_monthly_limit`, `monthly_limit` or `ip_not_allowed` |
475
+ | `NotFoundError` | 404 | `not_found` | No such job, endpoint or event on your account |
476
+ | `IdempotencyConflictError` (a `ConflictError`) | 409 | `idempotency_conflict` | The key was used before with a different request, or that request is still running |
477
+ | `JobNotCancellableError` (a `ConflictError`) | 409 | `job_not_cancellable` | The job is no longer queued |
478
+ | `ContentRefusedError` | 422 | `content_refused` | The request breaks the use rules |
479
+ | `RateLimitError` | 429 | `rate_limited` | Slow down; `err.retry_after` is in seconds |
480
+ | `ModelPausedError` | 503 | `model_paused` | Try again shortly or pick another model |
481
+ | `ServerError` | 500, 503 | `server_error` | A problem on our side, safe to retry |
482
+ | `APIConnectionError` / `APITimeoutError` | 0 | `network_error` / `timeout` | No answer came back |
483
+ | `WaitTimeoutError` | 0 | `wait_timeout` | `jobs.wait` gave up; `err.job` is the last state |
484
+
485
+ `WebhookVerificationError` (a `ValueError`) is raised by `webhooks.verify`.
486
+
487
+ ```python
488
+ import framera
489
+
490
+ try:
491
+ client.videos.create(prompt="…", duration_seconds=60)
492
+ except framera.InsufficientBalanceError:
493
+ notify_billing()
494
+ except framera.PermissionDeniedError as err:
495
+ if err.reason == "monthly_limit":
496
+ pause_until_next_month()
497
+ raise
498
+ except framera.ContentRefusedError as err:
499
+ ask_for_another_prompt(err.message)
500
+ ```
501
+
502
+ ## Retries and idempotency
503
+
504
+ The SDK retries rate limits (429), server errors (5xx) and network failures, twice by default, with exponential backoff and jitter. When the API sends `Retry-After`, the SDK waits exactly that long. Other errors are never retried. Calls that are not safe to repeat (creating a webhook endpoint, rolling its secret) are retried only on 429.
505
+
506
+ Every create carries an `Idempotency-Key`, so a retry never starts or charges for a second job. To make your own retries safe across restarts, pass a key you store:
507
+
508
+ ```python
509
+ client.videos.create(prompt="…", duration_seconds=60, idempotency_key=f"order-{order.id}")
510
+ ```
511
+
512
+ The same key with the same request returns the first job; the same key with a different request is an `IdempotencyConflictError`.
513
+
514
+ Rate limits: 120 requests a minute and 20 new jobs a minute per key. Every answer carries `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`.
515
+
516
+ ## Development
517
+
518
+ ```bash
519
+ python -m venv .venv
520
+ .venv/bin/pip install -e . pytest # Windows: .venv\Scripts\pip
521
+ .venv/bin/pytest
522
+ ```
523
+
524
+ The tests run against a fake API (httpx `MockTransport`) and a small local `http.server`; they never call Framera.
525
+
526
+ ## Use rules
527
+
528
+ Content made through the API follows the [Framera terms](https://framera.ai/terms), and the apps you build on it must pass these rules on to your users. No sexual content, no terrorist propaganda, no self-harm content, and no real people shown in a sexual or deceptive way.
529
+
530
+ ## Licence
531
+
532
+ MIT