Clients and tools
Python
The official Python client, sync and async.
astorie-client is the official Python client, imported as astorie_client. It has sync and async versions and full type hints.
Install
pip install astorie-client==0.1.0b1Requires Python 3.10 or later.
Configure
import os
from astorie_client import Astorie
client = Astorie(
api_key=os.environ["ASTORIE_API_KEY"],
base_url="https://astorie.ai/api/gateway",
timeout=60.0,
max_retries=3,
)With no arguments, Astorie() reads ASTORIE_API_KEY and ASTORIE_BASE_URL.
Run a model
inputs = {
"prompt": "A red chair in a sunlit studio",
"aspect_ratio": "1:1",
"resolution": "1K",
"output_format": "png",
}
result = client.run("google/nano-banana-2", inputs, max_charge_amount="1.000000")
job = result.job
if job["status"] == "succeeded":
client.download_asset(job["output"]["assets"][0], path="chair.png")Async
import asyncio
from astorie_client import AsyncAstorie
async def main():
async with AsyncAstorie() as client:
result = await client.run(
"google/nano-banana-2",
{"prompt": "A red chair", "aspect_ratio": "1:1", "resolution": "1K", "output_format": "png"},
max_charge_amount="1.000000",
)
print(result.job["status"])
asyncio.run(main())Methods
| Method | Calls |
|---|---|
list_models() | GET /v1/models |
get_model(model) | GET /v1/capabilities |
quote(model, input) | POST /v1/quotes |
get_quote(id) | GET /v1/quotes/{id} |
submit(model, input, max_charge_amount=, idempotency_key=, quote_id=, client_reference_id=) | POST /v1/jobs, returns a Submission |
get_job(id) | GET /v1/jobs/{id} |
list_jobs(limit=, cursor=) | GET /v1/jobs |
wait(id, timeout=, poll_interval=) | Polls get_job until the job is final |
run(model, input, ...) | submit, then wait, with the same key |
cancel(id) | POST /v1/jobs/{id}/cancel |
get_balance() | GET /v1/balance |
list_ledger(after_seq=, limit=) | GET /v1/ledger |
upload_file(path_or_bytes, mime_type=, filename=) | POST /v1/files, then the upload |
create_file(filename, mime_type, size_bytes) | POST /v1/files only |
download_asset(asset_or_url, path=) | Downloads a result as bytes, and writes it to path if given |
Behavior worth knowing
- Responses are plain dicts (typed as
TypedDict). Unknown fields are kept. - Passing a
floatfor money raisesTypeError. Use a string. timeoutapplies to each phase of a request (connect, read, write), so a slow upload isn't cut off while it is still moving.- A
failedjob is a return value ofwait(), not an exception. - If
wait()times out it raisesWaitTimeoutErrorwith.job_id. The job keeps running.