Skip to main content

Custom agents API

This page documents the 9 gateway endpoints tagged custom agents in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

MethodPathSummary
GET/v1/custom_agents/listList the custom agents the caller may see
GET/v1/custom_agents/infoRead one custom agent
POST/v1/custom_agents/newCreate a custom agent
POST/v1/custom_agents/updateReplace a custom agent's fields
POST/v1/custom_agents/deleteDelete a custom agent
POST/v1/custom_agents/runRun a custom agent
GET/v1/custom_agents/runsList custom agent runs
GET/v1/custom_agents/runs/infoRead one run with its events and transcript
POST/v1/custom_agents/runs/cancelCancel a running custom agent run

Endpoints​

GET /v1/custom_agents/list​

List the custom agents the caller may see

List the custom agents the caller may see and run. Proxy admins and admin viewers see all of them, everyone else sees agents shared with their organization, agents of their teams and their own private agents. Nothing changes. Docs (https://docs.spanway.ai/docs/proxy/custom_agents#who-can-do-what)

Example request:

curl -X GET "http://localhost:4000/v1/custom_agents/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The agents the caller may seeapplication/json array of CustomAgentSpec
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

GET /v1/custom_agents/info​

Read one custom agent

Read one custom agent: its instructions, model, tools, sharing and revision. An agent the caller may not see answers 404, the same as one that does not exist. Nothing changes. Docs (https://docs.spanway.ai/docs/proxy/custom_agents#create-an-agent)

Parameters:

NameInTypeRequiredDescription
agent_idquerystringYes

Example request:

curl -X GET "http://localhost:4000/v1/custom_agents/info?agent_id=agent_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The agentapplication/json CustomAgentSpec
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
agent_idstringYesAgent Id
agent_namestringYesAgent Name
namestringYesName
descriptionstring or nullYesDescription
revisionintegerYesRevision
instructionsstringYesInstructions
prompt_idstring or nullYesPrompt Id
prompt_versioninteger or nullYesPrompt Version
modelstringYesModel
toolset_idstring or nullYesToolset Id
write_toolsarray of WriteToolYesWrite Tools
builtin_toolsarray of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch"YesBuiltin Tools
skill_idsarray of stringYesSkill Ids
limitsRunLimitsYes
visibilityenum: "private", "team", "org"YesVisibility
owner_user_idstring or nullYesOwner User Id
owner_team_idstring or nullYesOwner Team Id
owner_organization_idstring or nullNoOwner Organization Id
templatestring or nullYesTemplate
enabledbooleanYesEnabled
created_bystringYesCreated By
updated_bystringYesUpdated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /v1/custom_agents/new​

Create a custom agent

Create a custom agent, an assistant built from instructions, a model and tools that runs through the gateway's own policies. Internal users create private agents, team admins also team agents for their teams, and only proxy admins share with everyone or turn on write tools. The creation is written to the audit log. Docs (https://docs.spanway.ai/docs/proxy/custom_agents#create-an-agent)

Request body (application/json, schema CustomAgentFields):

FieldTypeRequiredDescription
namestringYesName
descriptionstring or nullNoDescription
instructionsstringNoInstructions
prompt_idstring or nullNoPrompt Id
prompt_versioninteger or nullNoPrompt Version
modelstringYesModel
toolset_idstring or nullNoToolset Id
write_toolsarray of WriteToolNoWrite Tools
builtin_toolsarray of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch"NoBuiltin Tools
skill_idsarray of stringNoSkill Ids
limitsRunLimitsNo
visibilityenum: "private", "team", "org"NoVisibility
owner_team_idstring or nullNoOwner Team Id

Example request:

curl -X POST "http://localhost:4000/v1/custom_agents/new" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Release notes writer",
"description": "Drafts release notes from merged pull requests",
"instructions": "Read the merged pull requests and write short release notes grouped by area.",
"model": "claude-sonnet-5-5",
"toolset_id": "ts_01J...",
"limits": {
"max_steps": 12,
"max_run_budget": 0.5,
"max_wall_seconds": 300
},
"visibility": "private"
}'

Responses:

StatusDescriptionBody
200The new agentapplication/json CustomAgentSpec
400Model gpt-x does not exist or your key cannot call it or Prompt release-notes is not registered on the gateway or One or more skill_ids do not exist or The Lens tools need agent tracing, which is not enabled on this gateway or Server tools not enabled on this gateway: ['web_search'] or Write tools need a toolset that contains them or Write tools must be in the agent's toolset: [('gh', 'delete_repo')]application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404Toolset ts_01J... does not existapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
agent_idstringYesAgent Id
agent_namestringYesAgent Name
namestringYesName
descriptionstring or nullYesDescription
revisionintegerYesRevision
instructionsstringYesInstructions
prompt_idstring or nullYesPrompt Id
prompt_versioninteger or nullYesPrompt Version
modelstringYesModel
toolset_idstring or nullYesToolset Id
write_toolsarray of WriteToolYesWrite Tools
builtin_toolsarray of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch"YesBuiltin Tools
skill_idsarray of stringYesSkill Ids
limitsRunLimitsYes
visibilityenum: "private", "team", "org"YesVisibility
owner_user_idstring or nullYesOwner User Id
owner_team_idstring or nullYesOwner Team Id
owner_organization_idstring or nullNoOwner Organization Id
templatestring or nullYesTemplate
enabledbooleanYesEnabled
created_bystringYesCreated By
updated_bystringYesUpdated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /v1/custom_agents/update​

Replace a custom agent's fields

Replace every field of a custom agent and raise its revision. The caller needs the same rights as to create it in its sharing scope. When anyone but a proxy admin changes what the agent does, its write tools are switched off until a proxy admin turns them on again. The change is written to the audit log. Docs (https://docs.spanway.ai/docs/proxy/custom_agents#write-tools-are-off-by-default)

Request body (application/json, schema UpdateCustomAgentRequest):

FieldTypeRequiredDescription
namestringYesName
descriptionstring or nullNoDescription
instructionsstringNoInstructions
prompt_idstring or nullNoPrompt Id
prompt_versioninteger or nullNoPrompt Version
modelstringYesModel
toolset_idstring or nullNoToolset Id
write_toolsarray of WriteToolNoWrite Tools
builtin_toolsarray of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch"NoBuiltin Tools
skill_idsarray of stringNoSkill Ids
limitsRunLimitsNo
visibilityenum: "private", "team", "org"NoVisibility
owner_team_idstring or nullNoOwner Team Id
agent_idstringYesAgent Id

Example request:

curl -X POST "http://localhost:4000/v1/custom_agents/update" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51",
"name": "Release notes writer",
"description": "Drafts release notes from merged pull requests",
"instructions": "Read the merged pull requests and write short release notes grouped by area.",
"model": "claude-sonnet-5-5",
"toolset_id": "ts_01J...",
"limits": {
"max_steps": 12,
"max_run_budget": 0.5,
"max_wall_seconds": 300
},
"visibility": "private"
}'

Responses:

StatusDescriptionBody
200The agent after the changeapplication/json CustomAgentSpec
400Model gpt-x does not exist or your key cannot call it or Prompt release-notes is not registered on the gateway or One or more skill_ids do not exist or The Lens tools need agent tracing, which is not enabled on this gateway or Server tools not enabled on this gateway: ['web_search'] or Write tools need a toolset that contains them or Write tools must be in the agent's toolset: [('gh', 'delete_repo')]application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404Custom agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 not found or Toolset ts_01J... does not existapplication/json ErrorDetail
409Custom agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 was changed by someone else; reload it and try againapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
agent_idstringYesAgent Id
agent_namestringYesAgent Name
namestringYesName
descriptionstring or nullYesDescription
revisionintegerYesRevision
instructionsstringYesInstructions
prompt_idstring or nullYesPrompt Id
prompt_versioninteger or nullYesPrompt Version
modelstringYesModel
toolset_idstring or nullYesToolset Id
write_toolsarray of WriteToolYesWrite Tools
builtin_toolsarray of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch"YesBuiltin Tools
skill_idsarray of stringYesSkill Ids
limitsRunLimitsYes
visibilityenum: "private", "team", "org"YesVisibility
owner_user_idstring or nullYesOwner User Id
owner_team_idstring or nullYesOwner Team Id
owner_organization_idstring or nullNoOwner Organization Id
templatestring or nullYesTemplate
enabledbooleanYesEnabled
created_bystringYesCreated By
updated_bystringYesUpdated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /v1/custom_agents/delete​

Delete a custom agent

Delete a custom agent so nobody can run it again. The caller needs the same rights as to create it in its sharing scope. Its past runs stay readable to whoever started them and to admin viewers, and the deletion is written to the audit log. Docs (https://docs.spanway.ai/docs/proxy/custom_agents#who-can-do-what)

Request body (application/json, schema AgentIdRequest):

FieldTypeRequiredDescription
agent_idstringYesAgent Id

Example request:

curl -X POST "http://localhost:4000/v1/custom_agents/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51"
}'

Responses:

StatusDescriptionBody
200The agent as it was deletedapplication/json CustomAgentSpec
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
agent_idstringYesAgent Id
agent_namestringYesAgent Name
namestringYesName
descriptionstring or nullYesDescription
revisionintegerYesRevision
instructionsstringYesInstructions
prompt_idstring or nullYesPrompt Id
prompt_versioninteger or nullYesPrompt Version
modelstringYesModel
toolset_idstring or nullYesToolset Id
write_toolsarray of WriteToolYesWrite Tools
builtin_toolsarray of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch"YesBuiltin Tools
skill_idsarray of stringYesSkill Ids
limitsRunLimitsYes
visibilityenum: "private", "team", "org"YesVisibility
owner_user_idstring or nullYesOwner User Id
owner_team_idstring or nullYesOwner Team Id
owner_organization_idstring or nullNoOwner Organization Id
templatestring or nullYesTemplate
enabledbooleanYesEnabled
created_bystringYesCreated By
updated_bystringYesUpdated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /v1/custom_agents/run​

Run a custom agent

Run a custom agent with your own key. Model calls and tool calls go through the gateway's hooks, so your model access, budgets, guardrails, MCP grants and spend logs apply, narrowed further by the agent's toolset. With stream the response is server-sent events, one RunEvent per message, and disconnecting cancels the run. Otherwise the response is the final run.stopped event.

Request body (application/json, schema RunRequest):

FieldTypeRequiredDescription
agent_idstringYesAgent Id
inputstringYesInput
streambooleanNoStream

Example request:

curl -X POST "http://localhost:4000/v1/custom_agents/run" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51",
"input": "Write the notes for this week",
"stream": true
}'

Responses:

StatusDescriptionBody
200The finished run, or a stream of run events ending in run.stopped when stream is trueapplication/json RunStopped
400An agent's own key cannot run a custom agent; use a user or team keyapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403Agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 is not allowed for your key or team or Your key cannot call the agent's model gpt-x or Server tools not enabled for your key or team: ['web_search']application/json ErrorDetail
404Custom agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 not foundapplication/json ErrorDetail
409Custom agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 is disabled or Prompt release-notes is not registered on the gateway or Toolset ts_01J... no longer existsapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
429A rate or concurrency limit was reached, retry after Retry-After secondsapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
type"run.stopped"NoType
run_idstringYesRun Id
stop_reasonenum: "completed", "max_steps", "budget_exhausted", "killed", "cancelled", "deadline", "model_error"YesStop Reason
final_textstring or nullYesFinal Text
stepsintegerYesSteps
costnumberYesCost
detailstring or nullNoDetail

GET /v1/custom_agents/runs​

List custom agent runs

Runs newest first. Admin viewers see every run, everyone else only the runs they started, because a run holds what the gateway fetched with its caller's credentials.

Parameters:

NameInTypeRequiredDescription
agent_idquerystring or nullNo
pagequeryintegerNo

Example request:

curl -X GET "http://localhost:4000/v1/custom_agents/runs" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful responseapplication/json AgentRunPage
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
runsarray of RunSummaryYesRuns
pageintegerYesPage
has_morebooleanYesHas More

GET /v1/custom_agents/runs/info​

Read one run with its events and transcript

A run with every event and the transcript, for whoever started it and admin viewers. run_ledger_id opens the run in the run ledger, which joins its model requests, MCP calls and guardrail decisions from the spend logs.

Parameters:

NameInTypeRequiredDescription
run_idquerystringYes

Example request:

curl -X GET "http://localhost:4000/v1/custom_agents/runs/info?run_id=run_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful responseapplication/json RunDetail
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
runRunSummaryYes
eventsarray of RunStarted or StepStarted or ModelCompleted or ToolCalled or ToolDenied or RunStoppedYesEvents
transcriptarray of AgentSystemMessage or AgentUserMessage or AgentAssistantMessage or AgentToolMessageYesTranscript
run_ledger_idstringYesRun Ledger Id

POST /v1/custom_agents/runs/cancel​

Cancel a running custom agent run

Ask a running run to stop. It stops before its next model or tool call, on whichever replica runs it. The agent's managers may stop anyone's run of it but only get the run's status back, not its input or transcript.

Request body (application/json, schema RunIdRequest):

FieldTypeRequiredDescription
run_idstringYesRun Id

Example request:

curl -X POST "http://localhost:4000/v1/custom_agents/runs/cancel" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"run_id": "car_01J..."
}'

Responses:

StatusDescriptionBody
200Successful responseapplication/json RunDetail
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
runRunSummaryYes
eventsarray of RunStarted or StepStarted or ModelCompleted or ToolCalled or ToolDenied or RunStoppedYesEvents
transcriptarray of AgentSystemMessage or AgentUserMessage or AgentAssistantMessage or AgentToolMessageYesTranscript
run_ledger_idstringYesRun Ledger Id