In a generative video API, a typo is a line item. Send a duration of 300 where you meant 30 and a talking-actor job on Mantinea quotes 4,500 credits instead of 450. Forget the estimate_only flag on what was meant to be a dry run and a free quote becomes a $4.50 render. Retry a timed-out start without an idempotency key and you pay for the same ad twice. A typed client generated from Mantinea's OpenAPI 3.1 spec catches some of these at compile time and makes the rest hard to write by accident. Details are from Mantinea's public developer docs and its 24 November 2026 pricing; pull the live spec from https://app.mantinea.com/docs or the API and MCP help page before generating code.
What hand-written wrappers get wrong, priced
| Bug | What it costs | How a typed client plus wrappers prevents it |
|---|---|---|
| Duration 300 instead of 30 on a talking actor | 4,500 credits quoted instead of 450 | Quote-first wrapper with a budget ceiling rejects it |
| Lip-sync route where standard was meant | 1,200 credits instead of 450 for 30 s | Typed enum for the route, plus the quote check |
estimate_only left off a dry run | A real 450-credit render instead of a 0-credit quote | Wrapper that sets the flag, so a dry run cannot forget it |
| Retry without an idempotency key | A duplicate 450-credit render | Wrapper that requires a key from your job record |
Aspect ratio 4x5 instead of 4:5 | A rejected or failed request and lost time; failed jobs are refunded | Typed field accepts only 9:16, 1:1, 16:9, 4:5 |
| Client read timeout under 50 s on long-poll | Needless retries; dangerous if the start call is retried too | Explicit timeout above the 50 s server wait |
None of these needs a rare outage. They come from a tired engineer the Friday before a launch.
Step 1: pin the spec
Download the OpenAPI 3.1 JSON or YAML from Mantinea's developer docs and commit it, for example as specs/mantinea-openapi.json. Builds become reproducible and pull requests show when operations or parameters change.
Read three parts before running a generator: components.securitySchemes for the auth header and key format (keys are scoped read, generate or admin); paths for operation IDs and routes for starting jobs, batches of up to 50, long-poll status of up to 50 seconds and approvals; and shared parameters and headers, which show where estimate_only and idempotency keys go.
The spec also settles naming. Mantinea's developer surfaces still use the older "Autonomous" name in places, such as the webhook header X-Autonomous-Signature. A generated client uses the names the server expects today.
Step 2: TypeScript
For Node, Next.js or Workers, openapi-typescript with openapi-fetch produces types straight from the 3.1 schema with no runtime cost:
npm install --save-dev openapi-typescript
npm install openapi-fetch
npx openapi-typescript ./specs/mantinea-openapi.json -o ./src/lib/mantinea.d.ts
OpenAPI 3.1 uses JSON Schema 2020-12 (oneOf, anyOf, nullable types without the 3.0 quirks), so discriminated job payloads come out cleanly typed.
Step 3: Python
For pipelines and feed-to-ad workers, datamodel-code-generator (Pydantic v2 with httpx) or openapi-python-client both support 3.1:
pip install datamodel-code-generator httpx
datamodel-codegen --input ./specs/mantinea-openapi.json --input-file-type openapi \
--output ./mantinea_models.py --output-model-type pydantic_v2.BaseModel
Pydantic validates webhook payloads and responses strictly, and with httpx you control timeouts directly, which matters for the 50-second long-poll.
Step 4: three wrappers that enforce the budget
The generated client is low level. Put three helpers on top and make them the only way your scripts touch paid operations:
def quote(op, payload, ceiling):
q = client.call(op, {**payload, "estimate_only": True}) # 0 credits
if q.credits > ceiling:
raise OverBudget(op, q.credits, ceiling)
return q
def start(op, payload, job_row_id, ceiling):
quote(op, payload, ceiling)
return client.call(op, payload, idempotency_key=f"job-{job_row_id}")
def wait(job_id):
return client.get_job(job_id, wait=50, timeout=65) # timeout > 50 s
Method and field names here are placeholders for whatever your generator produced. Three facts shape the logic. Estimates run nothing and cost nothing. The Auto talking-actor route reserves at 40 credits a second even when it settles at 15, so check the balance covers the reserve. And the idempotency key comes from your job row, never from inside a retry loop; see idempotency keys in the Mantinea API.
For asynchronous pipelines, swap wait for registering the job with your webhook listener. To test raw payloads before setting up codegen, the curl quickstart shows the first calls.
A test suite that costs almost nothing
Put the wrappers under test with estimates, not renders. Because estimate_only calls run nothing, a CI job can price every job type your scripts use on each pull request and fail the build if a quote moves unexpectedly.
| Test | Call | Expected quote | Credits spent |
|---|---|---|---|
| 30 s standard talking actor | quote() | 450 | 0 |
| 30 s narrated | quote() | 90 | 0 |
| 3 s Hook lab opening | quote() | 36 | 0 |
| Duration 300 by mistake | quote() with a 600 ceiling | Raises OverBudget | 0 |
If a real end-to-end test is needed, use a script (3 credits) or a 10-second narrated clip (30 credits) on a staging workspace with a low spending cap.
Keeping the spec current
Once a month, or when you start using a newly shipped feature, diff the pinned spec against the live one at https://app.mantinea.com/docs, regenerate, and run tsc --noEmit or pytest in CI. A changed field then breaks a build instead of a client campaign.
What access costs
The full OpenAPI 3.1 API is on every Mantinea plan, from Starter ($29 a month, 2,900 credits) to Scale ($499, 55,000 credits), and on the 14-day trial (1,000 credits, no card). Some tools reserve API access for $550-a-month tiers or sell it as a separate developer subscription. A small agency can generate a typed client on day one, test with estimate_only for free, and build client handoffs without a second software bill.