Using Responses API
Use AnyRouter's Responses endpoint for modern agent and tool workflows with structured output items.
Use the Responses endpoint when your application benefits from a single response envelope with typed output items, tool calls, and optional reasoning metadata. This guide is for agent and tool builders deciding between endpoints, and shows a minimal working request.
Before you start
- An AnyRouter API key (prefixed
sk-ar-). Create one in the dashboard. - The OpenAI SDK, or any HTTP client — the Responses endpoint is OpenAI-compatible.
When to use Responses
| Use case | Recommended endpoint |
|---|---|
| Existing OpenAI chat app | Chat Completions |
| Anthropic Messages client | Messages |
| Agent or tool workflow | Responses |
| Model and price discovery | Models |
Reach for Responses when you want tool calls and reasoning kept in one typed output array — it makes multi-step agent loops easier to track than parsing chat deltas.
Minimal request
The Responses endpoint uses the same base URL and key as Chat Completions:
import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://anyrouter.dev/api/v1",
apiKey: process.env.ANYROUTER_API_KEY,
})
const response = await client.responses.create({
model: "openai/gpt-5.4-mini",
input: "Turn these notes into three action items.",
})
console.log(response.output_text)
curl https://anyrouter.dev/api/v1/responses \
-H "Authorization: Bearer sk-ar-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.4-mini",
"input": "Turn these notes into three action items."
}'
Add tools for agent loops
Responses keeps tool calls in the output array, which makes multi-step agent loops easier to track:
{
"model": "openai/gpt-5.4-mini",
"input": "Find the status of order 1234.",
"tools": [
{
"type": "function",
"name": "lookup_order",
"description": "Look up an order by id",
"parameters": {
"type": "object",
"properties": {
"order_id": { "type": "string" }
},
"required": ["order_id"]
}
}
],
"tool_choice": "auto"
}
Routing preferences
Responses accepts the same AnyRouter provider object as Chat Completions:
{
"provider": {
"sort": "latency",
"allow_fallbacks": true,
"max_price": {
"prompt": "2.00",
"completion": "8.00"
}
}
}
See Provider Routing for every field.
Verify
Send the minimal request above and confirm output_text (TypeScript) or a populated output array (curl) comes back.
Troubleshooting
output_text is empty but there was a tool call
When the model calls a tool, the answer lives in the output array as a tool-call item, not in output_text. Run the tool, append the result, and call again to get the final text.
Related
- Responses API — full request and response reference.
- Smart Routing — how AnyRouter picks an upstream.
- API Overview — all endpoints at a glance.