i2v-ai Python SDK
Server-side Python client for the i2v.ai image and video API. It mirrors the TypeScript SDK: quote before submitting, keep a stable idempotency key, and tell a pending submission apart from a definitive conflict.
- Python 3.10 or newer, no runtime dependencies.
- Covers model discovery, account balance and usage, quotes, uploads, task creation, polling, recovery, cancellation, and signed webhook verification.
Install
pip install ./packages/python-sdk
The package is not on PyPI yet; install it from this repository until it is.
Quickstart
import os
from i2v import I2VClient
client = I2VClient(api_key=os.environ["I2V_API_KEY"])
models = client.list_models().data["data"]
print([m["id"] for m in models if m["mediaType"] == "image"][:5])
quote = client.quote("gpt-image-2", {"prompt": "A ceramic mug on an oak table"}).data
print(quote["maximum"]) # maximum USD reservation for these inputs
print(quote["expectedRevision"]) # agree to this revision when submitting
list_models is public: it works without a key.
Submit inside a budget
receipt = client.create_task(
"gpt-image-2",
{"prompt": "A ceramic mug on an oak table"},
max_cost_usd="0.20",
expected_revision=quote["expectedRevision"],
idempotency_key="order-1234-image",
).data
print(receipt["taskId"])
result = client.wait_for_task(receipt["taskId"], timeout=900).data
print(result["status"], result.get("result"))
max_cost_usd is a decimal string. If the quote exceeds it, the API rejects the request before a task exists.
Recovery
A submission whose response was lost may still have been accepted. Look up the original receipt with the same key instead of sending a new request:
try:
task = client.create_task(..., idempotency_key="order-1234-image")
except I2VSubmissionUnknownError as error:
receipt = client.recover_submission(error.idempotency_key).data
# receipt["status"]: accepted | pending | retryable | missing
I2VSubmissionUnknownError.cause holds the original HTTP or network error, including retry_after_ms and request_id when the API sent them.
Webhooks
from i2v import verify_webhook
secrets = {"key_1": os.environ["I2V_WEBHOOK_SECRET"]}
verified = verify_webhook(
request.body, # exact raw bytes, before parsing
request.headers, # dict-like with the X-I2V-* headers
secrets.get,
max_age_seconds=300,
)
if verified is None:
raise PermissionError("untrusted delivery")
event = verified["body"] # eventId matches the header
The signature covers the timestamp, a dot, and the raw body, and the event ID in the body must match the header.
Errors
| Exception | Meaning |
|---|---|
I2VHttpError |
Non-2xx response. Carries status, code, reason, request_id, retry_after_ms. |
I2VSubmissionUnknownError |
The submission may be accepted (5xx, network failure, or HTTP 409 with submission_pending). Use recover_submission. |
I2VWaitTimeoutError |
The wait ended before the task reached a terminal state. |
I2VNetworkError |
No HTTP response. |
TypeError / ValueError |
Invalid local arguments, such as a non-HTTPS origin or a malformed budget. |
Tests
cd packages/python-sdk
python -m unittest discover -s tests -v
The tests run against a local HTTP server; they never call the real API and need no credentials.
Metadata
Release files for i2v-ai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| i2v_ai-0.1.0.tar.gz | 12.3 kB | Without provenance | Details for i2v_ai-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| i2v_ai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for i2v_ai-0.1.0-py3-none-any.whl |
Total release size: 21.5 kB
Release files / i2v_ai-0.1.0.tar.gz
| Download URL | i2v_ai-0.1.0.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4af08342887080d42319945a1aaf84f7a2185321e4dde8330b353bf6d51a0542
|
|
BLAKE2b-256 checksum How to use checksums |
8425328b6ad5a99562409e72918c1efc0a24b399144928ab3057ac6d522418f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / i2v_ai-0.1.0-py3-none-any.whl
| Download URL | i2v_ai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc3045cf1123f9b8e9f19e2fb120556c4ad8ddc7f63e8971f0a49bd6d3ea43d7
|
|
BLAKE2b-256 checksum How to use checksums |
242ee69059855bf31d3d2cb370ad4f4de0678f6c1dcde8d87cb3195d9aec4f1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Security for i2v-ai 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.