Basic Usage
Create simple text responses and read output content safely.
POST/v1/responses
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Required | Model ID |
input | string | Required | Prompt text |
max_output_tokens | integer | Upper bound for response token count |
Request Examples
cURL
curl https://api.therouter.ai/v1/responses \
-H "Authorization: Bearer $THEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4.5",
"input": "Write a three-line changelog entry.",
"max_output_tokens": 160
}'extract-output.ts
type OutputPart = { type: string; text?: string };
type OutputItem = { type: string; content?: OutputPart[] };
type ResponsePayload = { output?: OutputItem[] };
function getOutputText(response: ResponsePayload): string {
const message = response.output?.find((item) => item.type === "message");
const textPart = message?.content?.find((part) => part.type === "output_text");
return textPart?.text ?? "";
}Output Is Block-Based
The Responses API returns typed output blocks. Always select text from
output_text parts instead of assuming a single string field.