Point your OpenAI client at Realrouter.
The API keeps familiar OpenAI-style routes for responses, chat completions, files, and models. Replace the base URL, use your Realrouter key, and keep your client code small.
Quickstart
Install the official OpenAI SDK and set the Realrouter base URL. The dashboard will show your API key once when it is created.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.REALROUTER_KEY,
baseURL: "https://api.realrouter.org/v1",
});
const response = await client.responses.create({
model: "gpt-5.4-mini",
reasoning: { effort: "low" },
input: "Summarize this note in Chinese.",
});
console.log(response.output_text);Endpoints
POST /v1/responsesfor the primary OpenAI-compatible responses API.POST /v1/chat/completionsfor legacy chat completion clients.GET /v1/modelsfor available models, capabilities, and pricing metadata.
Tools and modalities
Realrouter forwards the tools parameter only for tool types it can translate into OpenAI-compatible request and streaming shapes. Unknown or unsupported tool types return 400 with unsupported_tool.
web_searchimage_generationfunctionWeb search
const response = await client.responses.create({
model: "gpt-5.3-codex-spark",
input: "Search the web and summarize today's top AI platform news.",
tools: [{ type: "web_search" }],
});Function calling
Function calling is stateless. Realrouter returns function_call items or chat tool_calls; your app runs the function and sends the result back with the relevant conversation context.
const first = await client.responses.create({
model: "gpt-5.5",
input: "What is the weather in Toronto?",
tools: [{
type: "function",
name: "get_weather",
description: "Get current weather for a city.",
parameters: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
additionalProperties: false,
},
}],
tool_choice: { type: "function", name: "get_weather" },
});
const call = first.output.find((item) => item.type === "function_call");
const toolResult = await getWeather(JSON.parse(call.arguments));
const final = await client.responses.create({
model: "gpt-5.5",
input: [
{ role: "user", content: "What is the weather in Toronto?" },
call,
{ type: "function_call_output", call_id: call.call_id, output: JSON.stringify(toolResult) },
],
tools: first.tools,
});Structured outputs
Responses supports OpenAI-compatible Structured Outputs with text.format.type=json_schema. Use json_schema when you need schema adherence; json_object remains available for plain JSON mode.
const response = await client.responses.create({
model: "gpt-5.4-mini",
input: "Extract the answer. Return exactly pong.",
text: {
format: {
type: "json_schema",
name: "pong_answer",
schema: {
type: "object",
properties: {
answer: { type: "string" },
},
required: ["answer"],
additionalProperties: false,
},
strict: true,
},
},
});
const parsed = JSON.parse(response.output_text);PDF and file input
curl https://api.realrouter.org/v1/files \
-H "Authorization: Bearer $REALROUTER_API_KEY" \
-F purpose=user_data \
-F file=@document.pdfconst response = await client.responses.create({
model: "gpt-5.4-mini",
input: [{
role: "user",
content: [
{ type: "input_file", file_id: "file-..." },
{ type: "input_text", text: "Summarize this PDF." },
],
}],
});Image generation
const response = await client.responses.create({
model: "gpt-5.4-mini",
input: "Generate a small product icon for a code API gateway.",
tools: [{ type: "image_generation" }],
});