Skip to main content

Built-in HTTP API

The default agent ships with three groups of HTTP endpoints alongside the A2A protocol routes:

GroupPath prefixPurpose
Query/api/v1/querySend a query, get a response (sync or SSE stream)
Chat history/api/v1/chat/historyList, read, create, and delete chat sessions
Health/api/v1/healthLiveness probe for orchestrators

A2A protocol routes (/.well-known/agent-card.json and the JSON-RPC endpoint) are mounted on the same server but are documented by the A2A spec and the Strands Agents SDK. This page covers the REST endpoints this repo defines directly.

Example URLs

Examples below use <AGENT_BASE_URL> for the agent's HTTP base. Substitute the URL your agent is reachable at — http://localhost:8000 for local dev (see the quickstart), or the deployed hostname for any other environment.

The OpenAPI spec at <AGENT_BASE_URL>/docs is the authoritative source for request/response shapes — this page is a concise reference and field guide.

Sync Query

POST /api/v1/query
Content-Type: application/json

Runs a single query through the agent and returns the full response when generation finishes. Use for one-shot calls where streaming offers no benefit (batch jobs, integrations, simple chat UIs).

Request body

FieldTypeRequiredConstraintsDescription
querystringyes1–8192 chars, non-whitespaceThe user's question
session_idstring | nullno8–128 chars, [A-Za-z0-9_-]+Persists conversation state across calls
contextobject | nullno≤32 keys, ≤16 KiB serialized, string keysFree-form metadata forwarded to the agent
max_resultsintno1–100, default 10Hint for retrieval-shaped tools
similarity_thresholdfloatno0.0–1.0, default 0.7Hint for retrieval-shaped tools

Response body — 200 OK

FieldTypeDescription
contentstringAgent-generated response text
session_idstring | nullEchoed from the request (or assigned by the agent)
processing_time_msfloatTotal wall-clock time for this query
timestampISO 8601 datetimeWhen the response was generated
metadataobject | nullBackend-specific extras (token usage, etc.)
correlation_idstring | nullServer-assigned ID for tracing
api_versionstringSchema version, currently "1.0"

Example

curl -X POST <AGENT_BASE_URL>/api/v1/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is machine learning?",
"session_id": "user-42-session-1"
}' | jq .

Streaming Query (SSE)

POST /api/v1/query/stream
Content-Type: application/json
Accept: text/event-stream

Streams response tokens as Server-Sent Events. Use for chat UIs where time-to-first-token matters.

The request body is identical to the sync endpoint. The response is text/event-stream with the following event types:

EventWhenPayload
tokenEach model output tokencontent, correlation_id, session_id
resultFinal assembled response (some backends)content, session_id, query_id, correlation_id, api_version
doneEnd of successful streamprocessing_time_ms, session_id, query_id, correlation_id, api_version
errorStream terminated with a failureerror, message, correlation_id, session_id, retryable
eventBackend event the API does not classifypayload (the raw event), correlation_id

Always close the stream when you receive done or error. retryable: true on an error indicates a transient failure (e.g., MCP reconnect) that a client may retry.

Example

curl -N -X POST <AGENT_BASE_URL>/api/v1/query/stream \
-H "Content-Type: application/json" \
-d '{"query": "Explain async/await in Python"}'
event: token
data: {"content": "Async", "correlation_id": "…", "session_id": null}

event: token
data: {"content": "/await", "correlation_id": "…", "session_id": null}



event: done
data: {"processing_time_ms": 1842.3, "session_id": null, "query_id": "…", "correlation_id": "…", "api_version": "1.0"}

Chat History

/api/v1/chat/history

CRUD over persisted chat sessions. Backed by the configured ChatHistoryManager (file or S3 by default; see Customizing the Server to plug in a custom store).

MethodPathPurpose
GET/api/v1/chat/historyList sessions (most recent first)
GET/api/v1/chat/history/{session_id}List messages in a session
PUT/api/v1/chat/history/{session_id}Create a session (idempotent)
DELETE/api/v1/chat/history/{session_id}Delete a session and its messages

session_id path parameters are 3–40 chars.

List sessions

GET /api/v1/chat/history?limit=20&offset=0

Query params: limit (1–100, optional) and offset (≥0, optional). Returns 200 OK with a list of Session objects:

FieldTypeDescription
session_idstringSession identifier
session_typestring"AGENT" for chat sessions
created_atISO 8601 stringCreation timestamp
updated_atISO 8601 stringLast modification timestamp

List messages in a session

GET /api/v1/chat/history/{session_id}?limit=50&offset=0

Messages are returned with the oldest first. Each SessionMessage:

FieldTypeDescription
messageobjectStrands Message (role + content blocks)
message_idintIndex of the message in conversation history
redact_messageobject | nullIf redacted, the content to show instead of message
created_atISO 8601 stringMessage creation timestamp
updated_atISO 8601 stringLast modification timestamp

Returns 404 Not Found if the session does not exist.

Create a session

PUT /api/v1/chat/history/{session_id}
  • 201 Created — session was created (response body is the new Session)
  • 200 OK — session already existed (response body is a Session stub)

Both successful responses set Content-Location: /chat/history/{session_id}.

Delete a session

DELETE /api/v1/chat/history/{session_id}
  • 204 No Content — session deleted
  • 404 Not Found — no session with that ID

Health

GET /api/v1/health

Returns {"status": "healthy"} (and additional readiness details) when the agent is ready to serve requests. Used by Docker, ECS, and Kubernetes probes — docker compose ps reports the container as healthy once this endpoint returns 200. Provided by foundry-agent-fastapi's health_router.

Error Format

All endpoints return errors in the same shape, produced by ErrorHandlingMiddleware:

{
"error": "ValidationError",
"message": "Query cannot be empty or whitespace only",
"details": null,
"correlation_id": "f1b3…",
"timestamp": "2026-06-26T12:34:56Z"
}

Common statuses:

StatusMeaning
400Domain validation rejected the request (also used for transient MCP failures with retryable: true)
404Session ID not found (chat history routes only)
422Pydantic request validation failed
500Unhandled server error

For streaming, the same shape arrives as the payload of an error SSE event.

OpenAPI / Swagger UI

While the server is running, browse the live spec:

  • Swagger UI<AGENT_BASE_URL>/docs
  • ReDoc<AGENT_BASE_URL>/redoc
  • OpenAPI JSON<AGENT_BASE_URL>/openapi.json