API reference

API reference · Agents

Start a hosted run

POST/v1/agents/{id}/runsAPI key

Hosted agent runs (lib/agent-runs.ts): the agent's definition runs a loop on the server, model call and tool calls, each step a job of its own. Every model call is a request by the agent's own key, billed to its wallet under its policy. The owner's key with the agents scope runs any of its agents; an agent's own key runs itself. Refused with 409 no_definition before a definition is stored, and with 429 too_many_active_runs past the agent's live runs. A 404 while hosted runs are off on the deployment.

Parameters

Path and query parameters
FieldTypeWhat it is
id (path)requiredstringThe agent's id; self on an agent's own key.

Request body

application/json, required

Request body fields
FieldTypeWhat it is
inputrequiredstring or array of objectThe user's message, or a list of { role: user | assistant, content } ending in the user's.
instructionsstring or nullAdded to the definition's for this run only.
metadataobject or null
limitsobject
limits.max_stepsinteger or nullModel calls and tool batches, together.
limits.max_wall_secondsinteger or nullWall clock from the run's creation.
limits.max_cost_microsinteger or nullWhat the run's model and image calls may be billed, in micro USD.

Example

{
  "input": "Say hello in five words.",
  "instructions": "string",
  "metadata": {},
  "limits": {
    "max_steps": 0,
    "max_wall_seconds": 0,
    "max_cost_micros": 0
  }
}

Answer 201

Started.

Fields of the 201 answer
FieldTypeWhat it is
objectstringOne of "agent.run".
idstring
agent_idinteger
statusstringOne of "queued", "in_progress", "requires_action", "cancelling", "completed", "incomplete", "failed", "cancelled", "expired".
modelstring
createdinteger
started_atinteger or null
completed_atinteger or null
expires_atinteger
stepsinteger
max_stepsinteger
max_wall_secondsinteger
cost_microsinteger
max_cost_microsinteger
usageobject
usage.prompt_tokensinteger
usage.completion_tokensinteger
output_textstring or null
required_actionobject or null
required_action.typestringOne of "submit_tool_outputs".
required_action.submit_tool_outputsobject
required_action.submit_tool_outputs.tool_callsarray of object
required_action.submit_tool_outputs.tool_calls[].idstring
required_action.submit_tool_outputs.tool_calls[].typestringOne of "function".
required_action.submit_tool_outputs.tool_calls[].functionobject
required_action.expires_atinteger or null
last_errorobject or null
last_error.codestring
last_error.messagestring
incomplete_detailsobject or null
incomplete_details.reasonstringOne of "max_steps", "max_wall_time", "max_cost".
metadataobject or null

Errors

  • 400OpenAI shaped error.
  • 401OpenAI shaped error.
  • 403OpenAI shaped error.
  • 404OpenAI shaped error.
  • 409OpenAI shaped error.
  • 429OpenAI shaped error.

Every error answers in one shape, with its type, code and the field it names. The whole list is in the docs' Errors section.

Antimatter