Responses
Create model responses using the OpenAI Responses API format with integrated tool calling, agentic multi-turn loops, streaming, and exact list pricing.
The /v1/responses endpoint supports the OpenAI Responses API format for autonomous agent loops, multi-step tool execution, and complex reasoning pipelines. Route requests across provider clouds with configurable fallback chains, safety guardrails, and exact provider list pricing with zero markup.
- Architectural Lifecycle: Preflight validates key ACLs, checks rate limits (
RPM/TPM), inspects content, and reserves token credit. Blocked requests return HTTP 400 (x-nr-guardrails: blocked) with $0 spent and $0 held. - Failover & Settlement: Failovers occur only where a fallback chain is configured (in Router Settings or
nrouter_fallbacks), and spend settles atomically at end-of-response.
POST https://api.nrouter.ai/v1/responsesRequest Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | Model ID (e.g. gpt-5.4-mini, gpt-4o). |
input | string or array | Yes | — | Input content string or array of input items. |
instructions | string | No | — | System-level guidance directing model behavior and tone. |
tools | array | No | — | Tools available to model (functions, code interpreter, web search). |
tool_choice | string or object | No | auto | Tool invocation mode (auto, required, none, or specific function). |
temperature | number | No | 1.0 | Sampling temperature between 0.0 and 2.0. |
max_output_tokens | integer | No | — | Maximum number of tokens to generate. |
stream | boolean | No | false | When true, streams response deltas via Server-Sent Events (SSE). |
nrouter_fallbacks | string[] | No | — | 1–4 fallback models if primary admission fails. |
nrouter_guardrails | string[] | No | — | 1–8 organization guardrail policy IDs. |
nrouter_cache | boolean | No | true | When false, bypasses the response cache. |
Examples
import { nRouter } from "@nrouter_ai/sdk";
const client = new nRouter({ apiKey: process.env.NROUTER_API_KEY });
const res = await client.responses.create({
model: "gpt-5.4-mini",
input: "Summarize incident root cause.",
});
console.log(res.output[0].content[0].text, client.lastResponse?.cost);Headers & Errors
Inbound: Authorization: Bearer sk-nrouter-... and Content-Type: application/json. Optional: x-nr-tags, x-nr-compress. Telemetry: x-nr-request-id, x-nr-latency-ms, x-nr-request-cost, x-nr-cost-status, x-nr-model, x-nr-routing, x-nr-attempts, x-nr-guardrails, x-nr-response-cache. See Chat Completions.
| HTTP Status | Error Code | Reason |
|---|---|---|
| 400 Bad Request | invalid_request | Missing required input or model fields, or invalid tool schemas. |
| 400 Bad Request | guardrail_blocked | Preflight inspection detected prompt injection or safety policy violation. |
| 401 Unauthorized | invalid_api_key | Virtual key missing, expired, or invalid. |
| 402 Payment Required | insufficient_credits | Organization balance is insufficient to reserve token hold. |
| 404 Not Found | model_not_found | Model identifier not found or unauthorized for tenant. |
| 429 Too Many Requests | rate_limit_exceeded | Virtual key or organization RPM/TPM ceiling exceeded. |
| 500 / 503 Provider Error | service_unavailable | Upstream outage. 503 triggers fallback only where configured (nrouter_fallbacks). |
Authorization
NRouterApiKey Your nRouter virtual key (sk-nrouter-…). Sent as Authorization: Bearer sk-nrouter-….
In: header
Header Parameters
Request prompt compression: on to compress eligible prompts, off to skip
Value in
- "on"
- "off"
Target MCP server ID when routing MCP tool calls or prompts through the gateway
Caller SDK runtime language identification (e.g. typescript, python, rust, go)
Caller session identifier allowed at edge for grouping related client turns
Inbound trace detail level override for request lifecycle spans
Value in
- "off"
- "stages"
- "verbose"
Inbound stage-level trace emission override
Value in
- "off"
- "stages"
- "verbose"
Accepted so a client sending it is not refused; the value is not recorded and not propagated. Every response carries the gateway's own trace ID in this header, never the one sent.
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/responses" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5.4-mini", "input": "Explain how prompt injection defense operates before credit reservation." }'{ "id": "resp_01", "object": "response", "status": "completed", "output": [ { "type": "message", "role": "assistant", "content": [ { "type": "output_text", "text": "Hello!" } ] } ]}