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.
| Method | Path | Summary |
|---|---|---|
| GET | /v1/custom_agents/list | List the custom agents the caller may see |
| GET | /v1/custom_agents/info | Read one custom agent |
| POST | /v1/custom_agents/new | Create a custom agent |
| POST | /v1/custom_agents/update | Replace a custom agent's fields |
| POST | /v1/custom_agents/delete | Delete a custom agent |
| POST | /v1/custom_agents/run | Run a custom agent |
| GET | /v1/custom_agents/runs | List custom agent runs |
| GET | /v1/custom_agents/runs/info | Read one run with its events and transcript |
| POST | /v1/custom_agents/runs/cancel | Cancel 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:
| Status | Description | Body |
|---|---|---|
| 200 | The agents the caller may see | application/json array of CustomAgentSpec |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
agent_id | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/v1/custom_agents/info?agent_id=agent_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The agent | application/json CustomAgentSpec |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent Id |
agent_name | string | Yes | Agent Name |
name | string | Yes | Name |
description | string or null | Yes | Description |
revision | integer | Yes | Revision |
instructions | string | Yes | Instructions |
prompt_id | string or null | Yes | Prompt Id |
prompt_version | integer or null | Yes | Prompt Version |
model | string | Yes | Model |
toolset_id | string or null | Yes | Toolset Id |
write_tools | array of WriteTool | Yes | Write Tools |
builtin_tools | array of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch" | Yes | Builtin Tools |
skill_ids | array of string | Yes | Skill Ids |
limits | RunLimits | Yes | |
visibility | enum: "private", "team", "org" | Yes | Visibility |
owner_user_id | string or null | Yes | Owner User Id |
owner_team_id | string or null | Yes | Owner Team Id |
owner_organization_id | string or null | No | Owner Organization Id |
template | string or null | Yes | Template |
enabled | boolean | Yes | Enabled |
created_by | string | Yes | Created By |
updated_by | string | Yes | Updated By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated 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):
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name |
description | string or null | No | Description |
instructions | string | No | Instructions |
prompt_id | string or null | No | Prompt Id |
prompt_version | integer or null | No | Prompt Version |
model | string | Yes | Model |
toolset_id | string or null | No | Toolset Id |
write_tools | array of WriteTool | No | Write Tools |
builtin_tools | array of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch" | No | Builtin Tools |
skill_ids | array of string | No | Skill Ids |
limits | RunLimits | No | |
visibility | enum: "private", "team", "org" | No | Visibility |
owner_team_id | string or null | No | Owner 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:
| Status | Description | Body |
|---|---|---|
| 200 | The new agent | application/json CustomAgentSpec |
| 400 | Model 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 |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | Toolset ts_01J... does not exist | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent Id |
agent_name | string | Yes | Agent Name |
name | string | Yes | Name |
description | string or null | Yes | Description |
revision | integer | Yes | Revision |
instructions | string | Yes | Instructions |
prompt_id | string or null | Yes | Prompt Id |
prompt_version | integer or null | Yes | Prompt Version |
model | string | Yes | Model |
toolset_id | string or null | Yes | Toolset Id |
write_tools | array of WriteTool | Yes | Write Tools |
builtin_tools | array of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch" | Yes | Builtin Tools |
skill_ids | array of string | Yes | Skill Ids |
limits | RunLimits | Yes | |
visibility | enum: "private", "team", "org" | Yes | Visibility |
owner_user_id | string or null | Yes | Owner User Id |
owner_team_id | string or null | Yes | Owner Team Id |
owner_organization_id | string or null | No | Owner Organization Id |
template | string or null | Yes | Template |
enabled | boolean | Yes | Enabled |
created_by | string | Yes | Created By |
updated_by | string | Yes | Updated By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated 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):
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name |
description | string or null | No | Description |
instructions | string | No | Instructions |
prompt_id | string or null | No | Prompt Id |
prompt_version | integer or null | No | Prompt Version |
model | string | Yes | Model |
toolset_id | string or null | No | Toolset Id |
write_tools | array of WriteTool | No | Write Tools |
builtin_tools | array of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch" | No | Builtin Tools |
skill_ids | array of string | No | Skill Ids |
limits | RunLimits | No | |
visibility | enum: "private", "team", "org" | No | Visibility |
owner_team_id | string or null | No | Owner Team Id |
agent_id | string | Yes | Agent 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:
| Status | Description | Body |
|---|---|---|
| 200 | The agent after the change | application/json CustomAgentSpec |
| 400 | Model 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 |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | Custom agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 not found or Toolset ts_01J... does not exist | application/json ErrorDetail |
| 409 | Custom agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 was changed by someone else; reload it and try again | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent Id |
agent_name | string | Yes | Agent Name |
name | string | Yes | Name |
description | string or null | Yes | Description |
revision | integer | Yes | Revision |
instructions | string | Yes | Instructions |
prompt_id | string or null | Yes | Prompt Id |
prompt_version | integer or null | Yes | Prompt Version |
model | string | Yes | Model |
toolset_id | string or null | Yes | Toolset Id |
write_tools | array of WriteTool | Yes | Write Tools |
builtin_tools | array of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch" | Yes | Builtin Tools |
skill_ids | array of string | Yes | Skill Ids |
limits | RunLimits | Yes | |
visibility | enum: "private", "team", "org" | Yes | Visibility |
owner_user_id | string or null | Yes | Owner User Id |
owner_team_id | string or null | Yes | Owner Team Id |
owner_organization_id | string or null | No | Owner Organization Id |
template | string or null | Yes | Template |
enabled | boolean | Yes | Enabled |
created_by | string | Yes | Created By |
updated_by | string | Yes | Updated By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated 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):
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent 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:
| Status | Description | Body |
|---|---|---|
| 200 | The agent as it was deleted | application/json CustomAgentSpec |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent Id |
agent_name | string | Yes | Agent Name |
name | string | Yes | Name |
description | string or null | Yes | Description |
revision | integer | Yes | Revision |
instructions | string | Yes | Instructions |
prompt_id | string or null | Yes | Prompt Id |
prompt_version | integer or null | Yes | Prompt Version |
model | string | Yes | Model |
toolset_id | string or null | Yes | Toolset Id |
write_tools | array of WriteTool | Yes | Write Tools |
builtin_tools | array of enum: "lens_recent_traces", "lens_read_trace", "lens_read_span", "server_datetime", "server_web_fetch" | Yes | Builtin Tools |
skill_ids | array of string | Yes | Skill Ids |
limits | RunLimits | Yes | |
visibility | enum: "private", "team", "org" | Yes | Visibility |
owner_user_id | string or null | Yes | Owner User Id |
owner_team_id | string or null | Yes | Owner Team Id |
owner_organization_id | string or null | No | Owner Organization Id |
template | string or null | Yes | Template |
enabled | boolean | Yes | Enabled |
created_by | string | Yes | Created By |
updated_by | string | Yes | Updated By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated 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):
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent Id |
input | string | Yes | Input |
stream | boolean | No | Stream |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The finished run, or a stream of run events ending in run.stopped when stream is true | application/json RunStopped |
| 400 | An agent's own key cannot run a custom agent; use a user or team key | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | Agent 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 |
| 404 | Custom agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 not found | application/json ErrorDetail |
| 409 | Custom agent 5b7e2c41-9d3a-4f6e-8c12-7a9b0d3e4f51 is disabled or Prompt release-notes is not registered on the gateway or Toolset ts_01J... no longer exists | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 429 | A rate or concurrency limit was reached, retry after Retry-After seconds | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
type | "run.stopped" | No | Type |
run_id | string | Yes | Run Id |
stop_reason | enum: "completed", "max_steps", "budget_exhausted", "killed", "cancelled", "deadline", "model_error" | Yes | Stop Reason |
final_text | string or null | Yes | Final Text |
steps | integer | Yes | Steps |
cost | number | Yes | Cost |
detail | string or null | No | Detail |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
agent_id | query | string or null | No | |
page | query | integer | No |
Example request:
curl -X GET "http://localhost:4000/v1/custom_agents/runs" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json AgentRunPage |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
runs | array of RunSummary | Yes | Runs |
page | integer | Yes | Page |
has_more | boolean | Yes | Has 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | query | string | Yes |
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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json RunDetail |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
run | RunSummary | Yes | |
events | array of RunStarted or StepStarted or ModelCompleted or ToolCalled or ToolDenied or RunStopped | Yes | Events |
transcript | array of AgentSystemMessage or AgentUserMessage or AgentAssistantMessage or AgentToolMessage | Yes | Transcript |
run_ledger_id | string | Yes | Run 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):
| Field | Type | Required | Description |
|---|---|---|---|
run_id | string | Yes | Run 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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json RunDetail |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | application/json ErrorDetail |
| 409 | The object already exists or is in a state that does not allow this change | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
run | RunSummary | Yes | |
events | array of RunStarted or StepStarted or ModelCompleted or ToolCalled or ToolDenied or RunStopped | Yes | Events |
transcript | array of AgentSystemMessage or AgentUserMessage or AgentAssistantMessage or AgentToolMessage | Yes | Transcript |
run_ledger_id | string | Yes | Run Ledger Id |