Agents
Run a server-side agent synchronously or as an async run you poll, stream or cancel.
The agents API wraps the gateway's own tool-using loop. Synchronous runs return the answer inline; async runs return 202 with an id you poll, stream over SSE (full replay on reconnect — no Last-Event-ID) or cancel. Concepts and limits: agents guide.
bearerAuthAuthorizationBearer <codai_…>A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).
x-request-id?stringClient correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128application/json- body
Body of POST /v1/agents/run.
task*stringThe goal, in natural language. Becomes the user turn.
1 <= length <= 64000context?stringOptional supporting material, appended to the task under a ## Context heading.
length <= 256000system?stringOptional system-prompt override, sent as the first message before the agent scaffold.
length <= 32000model?stringModel alias to route through.
length <= 128"codai"max_steps?integerRequested agent-loop depth cap. Validated but not enforced — the tier's agent-mode depth applies.
1 <= value <= 16The completed run.
application/json- response
Response of POST /v1/agents/run.
result*stringThe final assistant answer (empty string when the model produced no content).
status*"completed""completed"usage*Aggregate token counts for the whole run.
model*stringConcrete upstream model that served the final turn.
event_id*|Usage event id for feedback correlation; null when none was written.
uuidcurl -X POST 'https://ai.codai.ro/v1/agents/run' \ -H 'Content-Type: application/json' \ -d '{ "task": "Find the three most recent BNR EUR/RON rates and summarise the trend."}'{ "result": "string", "status": "completed", "usage": { "prompt_tokens": 0, "completion_tokens": 0 }, "model": "string", "event_id": "a7a26ff2-e851-45b6-9634-d595f45458b7"}bearerAuthAuthorizationBearer <codai_…>A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).
x-request-id?stringClient correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128application/json- body
Body of POST /v1/agents/runs; extends the synchronous request.
task*stringThe goal, in natural language. Becomes the user turn.
1 <= length <= 64000context?stringOptional supporting material, appended to the task under a ## Context heading.
length <= 256000system?stringOptional system-prompt override, sent as the first message before the agent scaffold.
length <= 32000model?stringModel alias to route through.
length <= 128"codai"max_steps?integerRequested agent-loop depth cap. Validated but not enforced — the tier's agent-mode depth applies.
1 <= value <= 16budget_seconds?integerRequested wall-clock budget. Stored (default 300) but not enforced.
10 <= value <= 1800client_request_id?stringIdempotency key scoped to your user — a repeat returns the existing run id.
length <= 200Run accepted and queued.
application/json- response
Response of POST /v1/agents/runs (HTTP 202).
id*stringuuidstatus*"queued"Always queued at submit time, even when an idempotent repeat hits a run that has since progressed.
"queued"poll*stringRelative URL of the poll endpoint for this run.
curl -X POST 'https://ai.codai.ro/v1/agents/runs' \ -H 'Content-Type: application/json' \ -d '{ "task": "Find the three most recent BNR EUR/RON rates and summarise the trend."}'{ "id": "3f9d2c1e-7b4a-4e0f-9a1d-2c5b6e7f8a90", "status": "queued", "poll": "/v1/agents/runs/3f9d2c1e-7b4a-4e0f-9a1d-2c5b6e7f8a90"}bearerAuthAuthorizationBearer <codai_…>A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).
days?integerWindow length in days, clamped to 1–90.
1 <= value <= 907x-request-id?stringClient correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128Aggregates for the window.
application/json- response
Aggregates over your runs in the window. Only window_days and total are guaranteed; the remaining
fields are absent for legacy compatibility keys that cannot own persisted runs.
window_days*integer1 <= value <= 90total*integer0 <= valuecompleted?integer0 <= valuefailed?integer0 <= valuecancelled?integer0 <= valuein_flight?integerRuns currently queued or running.
0 <= valueprompt_tokens?integer0 <= valuecompletion_tokens?integer0 <= valueavg_steps?integerRounded average of step_count.
0 <= valueavg_latency_ms?integerRounded average of finished_at - started_at over finished runs.
0 <= valuecurl -X GET 'https://ai.codai.ro/v1/agents/runs/stats'{ "window_days": 1, "total": 0, "completed": 0, "failed": 0, "cancelled": 0, "in_flight": 0, "prompt_tokens": 0, "completion_tokens": 0, "avg_steps": 0, "avg_latency_ms": 0}bearerAuthAuthorizationBearer <codai_…>A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).
id*stringAgent run UUID returned by POST /v1/agents/runs.
uuidx-request-id?stringClient correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128The run.
application/json- response
Poll view of a persisted run (GET /v1/agents/runs/{id}).
id*stringuuidstatus*AgentRunStatusRun lifecycle — queued → running → one of completed, failed, cancelled.
"queued""running""completed""failed""cancelled"task*stringThe submitted goal, verbatim.
model*|Requested model alias (codai when omitted at submit).
result*|Final answer; set only once status is completed.
error*|Failure message (≤ 2000 chars); set only when status is failed.
step_count*integerLoop steps executed so far. Not incremented by the current executor.
0 <= valueusage*Aggregate token counts for the whole run.
created_at*stringdate-timestarted_at*|When execution was claimed; null while queued.
date-timefinished_at*|Set on completed, failed and cancelled.
date-timecurl -X GET 'https://ai.codai.ro/v1/agents/runs/497f6eca-6276-4993-bfeb-53cbbbba6f08'{ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "status": "queued", "task": "string", "model": "string", "result": "string", "error": "string", "step_count": 0, "usage": { "prompt_tokens": 0, "completion_tokens": 0 }, "created_at": "2019-08-24T14:15:22Z", "started_at": "2019-08-24T14:15:22Z", "finished_at": "2019-08-24T14:15:22Z"}bearerAuthAuthorizationBearer <codai_…>A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).
id*stringAgent run UUID returned by POST /v1/agents/runs.
uuidx-request-id?stringClient correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128The step trace.
application/json- response
id*stringThe run id.
uuidsteps*array<>curl -X GET 'https://ai.codai.ro/v1/agents/runs/497f6eca-6276-4993-bfeb-53cbbbba6f08/steps'{ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "steps": [ { "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "runId": "78c33d18-170c-44d3-a227-b3194f134f73", "seq": 0, "kind": "plan", "summary": "string", "detail": null, "latencyMs": 0, "createdAt": "2019-08-24T14:15:22Z" } ]}bearerAuthAuthorizationBearer <codai_…>A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).
id*stringAgent run UUID returned by POST /v1/agents/runs.
uuidx-request-id?stringClient correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128SSE stream; see the description for event names and payloads.
response?stringtext/event-streamcurl -X GET 'https://ai.codai.ro/v1/agents/runs/497f6eca-6276-4993-bfeb-53cbbbba6f08/stream'"string"bearerAuthAuthorizationBearer <codai_…>A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).
id*stringAgent run UUID returned by POST /v1/agents/runs.
uuidx-request-id?stringClient correlation id; echoed back as x-codai-trace-id and persisted on the usage row.
length <= 128The run is now cancelled.
application/json- response
id*stringuuidstatus*"cancelled""cancelled"curl -X POST 'https://ai.codai.ro/v1/agents/runs/497f6eca-6276-4993-bfeb-53cbbbba6f08/cancel'{ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "status": "cancelled"}Last updated: