Basic Usage

Create simple text responses and read output content safely.

POST/v1/responses
NameTypeRequiredDescription
model
stringRequiredModel ID
input
stringRequiredPrompt text
max_output_tokens
integerUpper 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 fromoutput_text parts instead of assuming a single string field.