On this page
agents.create
Create an agent from a template (201; an idempotent replay returns 200)
Request
POST /api/v1/agents
- MCP:
agents_create - SDK:
client.agents.create(SDK path arguments usepath; MCP usesparams). - Minimum API key role: member.
- Idempotency: required_header. Send an
Idempotency-Keyheader; MCP usesidempotency_key. Reuse it after an unknown outcome.
template phone_outbound starts an outbound phone agent; cloud_task and cloud_chat start cloud agents; blank is an empty flow. The result's ref.id is the agent_id and draft {draft_id, revision} is its first draft: change it with drafts_edit, check it with drafts_validate.
Input schema
json
{
"parameters": [
{
"name": "Idempotency-Key",
"in": "header",
"required": true,
"schema": {
"type": "string",
"minLength": 1,
"maxLength": 256
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AgentsCreateRequest"
}
}
}
}
}
Responses
json
{
"200": {
"description": "Create an agent from a template (201; an idempotent replay returns 200)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AgentSummary"
}
}
}
},
"201": {
"description": "Create an agent from a template (201; an idempotent replay returns 200)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AgentSummary"
}
}
}
},
"4XX": {
"description": "Typed error (ApiError)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiError"
}
}
}
},
"5XX": {
"description": "Typed error (ApiError)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiError"
}
}
}
}
}
Referenced schemas
json
{
"components": {
"schemas": {
"AgentsCreateRequest": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 256
},
"template": {
"type": "string",
"enum": [
"blank",
"cloud_task",
"cloud_chat",
"phone_outbound"
]
},
"channels": {
"type": "array",
"items": {
"type": "string",
"enum": [
"cloud",
"phone"
]
},
"minItems": 1
},
"languages": {
"type": "array",
"items": {
"type": "string",
"enum": [
"en",
"es"
]
},
"minItems": 1,
"default": [
"en"
]
}
},
"required": [
"name",
"template",
"channels"
],
"additionalProperties": false
},
"AgentSummary": {
"type": "object",
"properties": {
"ref": {
"type": "object",
"properties": {
"tenant_id": {
"type": "string",
"format": "uuid"
},
"kind": {
"type": "string",
"enum": [
"agent"
]
},
"id": {
"type": "string",
"minLength": 1,
"maxLength": 256,
"pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]*$"
}
},
"required": [
"tenant_id",
"kind",
"id"
],
"additionalProperties": false
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 256
},
"head": {
"type": "object",
"properties": {
"version": {
"type": "integer",
"minimum": 0,
"maximum": 2147483647
},
"digest": {
"type": "string",
"pattern": "^sha256:[a-f0-9]{64}$"
},
"channels": {
"type": "array",
"items": {
"type": "string",
"enum": [
"cloud",
"phone"
]
},
"minItems": 1
},
"languages": {
"type": "array",
"items": {
"type": "string",
"enum": [
"en",
"es"
]
},
"minItems": 1
},
"published_at": {
"type": "string",
"format": "date-time"
}
},
"required": [
"version",
"digest",
"channels",
"languages",
"published_at"
],
"additionalProperties": false,
"nullable": true
},
"draft": {
"type": "object",
"properties": {
"draft_id": {
"type": "string",
"format": "uuid"
},
"revision": {
"type": "integer",
"exclusiveMinimum": true,
"minimum": 0
},
"base_version": {
"allOf": [
{
"type": "integer",
"minimum": 0,
"maximum": 2147483647
}
],
"nullable": true
},
"published_revision": {
"type": "integer",
"exclusiveMinimum": true,
"minimum": 0,
"nullable": true
}
},
"required": [
"draft_id",
"revision",
"base_version",
"published_revision"
],
"additionalProperties": false,
"nullable": true
},
"created_at": {
"type": "string",
"format": "date-time"
},
"updated_at": {
"type": "string",
"format": "date-time",
"description": "The head's publish time, else created_at: the key of the updated_desc agents.list order"
},
"last_run": {
"type": "object",
"properties": {
"run_id": {
"type": "string",
"format": "uuid"
},
"created_at": {
"type": "string",
"format": "date-time"
},
"state": {
"type": "string",
"enum": [
"admitted",
"running",
"ending",
"completed",
"failed",
"cancelled",
"rejected",
"expired"
]
},
"disposition": {
"type": "string",
"nullable": true
}
},
"required": [
"run_id",
"created_at",
"state",
"disposition"
],
"additionalProperties": false,
"nullable": true,
"description": "The most recent non-test run of any version; null when the agent never ran outside Studio tests"
}
},
"required": [
"ref",
"name",
"head",
"draft",
"created_at",
"updated_at",
"last_run"
],
"additionalProperties": false
},
"ApiError": {
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": [
"unauthenticated",
"forbidden",
"not_found",
"conflict",
"invalid_request",
"idempotency_conflict",
"policy_denied",
"capability_unavailable",
"provider_unavailable",
"knowledge_unavailable",
"publication_invalid",
"run_not_active",
"rate_limited",
"outcome_unknown",
"internal"
]
},
"message": {
"type": "string"
},
"retryable": {
"type": "boolean"
},
"outcome": {
"type": "string",
"enum": [
"none",
"unknown"
]
},
"details": {
"type": "object",
"additionalProperties": {}
}
},
"required": [
"code",
"message",
"retryable",
"outcome"
],
"additionalProperties": false
}
},
"required": [
"error"
],
"additionalProperties": false
}
}
}
}
Errors and recovery
See API error handling and Troubleshooting.
Related guides
Content version 416f545dMarkdown source