API formats
OpenAI compatibility
LLM Router serves OpenAI-compatible endpoints, so you can use the OpenAI SDK for chat completions, responses, and moderations. With the base URL and authentication settings below, you can add the capabilities of LLM Router to your existing apps.
Credential handling
Run these examples on your server. Set INWORLD_API_KEY to the complete Base64 credentials copied from Portal or the CLI, without encoding them again. The examples set an explicit Authorization: Basic ... header. The router also accepts the same credential as Authorization: Bearer ..., which is what the OpenAI SDK sends from api_key. Browser/mobile clients need a backend-minted token, never the server API key.
Endpoint
The OpenAI-compatible API endpoint is available at:
https://api.inworld.ai/v1To use LLM Router, change your API call URL or SDK base URL from https://api.openai.com/v1 to https://api.inworld.ai/v1.
Supported endpoints
| Endpoint | SDK method | Guide |
|---|---|---|
POST /v1/chat/completions | client.chat.completions.create | Text chat |
POST /v1/responses and /v1/responses/{response_id} endpoints | client.responses.* | Responses API |
POST /v1/moderations | client.moderations.create | Moderation |
The router does not serve other OpenAI endpoints, including /v1/models (client.models.list() returns 404), /v1/batches, /v1/embeddings, and the file and image endpoints. To list available models, use the List Models API. For text-to-speech in OpenAI's /v1/audio/speech format, see TTS OpenAI compatibility.
OpenAI SDK
Below is an example request using OpenAI's SDK
import os
from openai import OpenAI
api_key = os.environ["INWORLD_API_KEY"]
# Initialize the client with LLM Router credentials
client = OpenAI(
base_url="https://api.inworld.ai/v1",
api_key=api_key,
default_headers={"Authorization": f"Basic {api_key}"},
)
# Call your router
response = client.chat.completions.create(
model="inworld/<router-id>",
messages=[
{"role": "user", "content": "Who created you?"}
]
)
print(response.choices[0].message.content)import OpenAI from 'openai';
const apiKey = process.env.INWORLD_API_KEY;
if (!apiKey) throw new Error('Set INWORLD_API_KEY to your copied Base64 credential');
const openai = new OpenAI({
baseURL: 'https://api.inworld.ai/v1',
apiKey,
defaultHeaders: { Authorization: `Basic ${apiKey}` },
});
async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: 'user', content: 'Who created you?' }],
model: 'inworld/demo-router'
});
console.log(completion.choices[0].message.content);
}
main();Responses API
The same client works with the Responses API:
response = client.responses.create(
model="inworld/<router-id>",
input="Who created you?",
)
print(response.output_text)See the Responses API guide for streaming, tools, and stored responses.