OpenAI-Compatible Clients

Routero exposes a fully OpenAI-compatible API. Any language with an OpenAI SDK works out of the box — change base_url, keep everything else.


Python (openai package)

import openai

client = openai.OpenAI(
    api_key="YOUR_ROUTERO_KEY",
    base_url="https://api.routero.ai/v1",
)

response = client.chat.completions.create(
    model="smart/balanced",
    messages=[{"role": "user", "content": "Hello!"}],
)

TypeScript / Node (openai npm package)

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_ROUTERO_KEY",
  baseURL: "https://api.routero.ai/v1",
});

const response = await client.chat.completions.create({
  model: "smart/balanced",
  messages: [{ role: "user", content: "Hello!" }],
});

Go (sashabaranov/go-openai)

import "github.com/sashabaranov/go-openai"

config := openai.DefaultConfig("YOUR_ROUTERO_KEY")
config.BaseURL = "https://api.routero.ai/v1"
client := openai.NewClientWithConfig(config)

resp, err := client.CreateChatCompletion(
    context.Background(),
    openai.ChatCompletionRequest{
        Model: "smart/balanced",
        Messages: []openai.ChatCompletionMessage{
            {Role: openai.ChatMessageRoleUser, Content: "Hello!"},
        },
    },
)

curl / any HTTP client

curl https://api.routero.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_ROUTERO_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "smart/balanced", "messages": [{"role": "user", "content": "Hello!"}]}'

Advanced Features with OpenAI clients

Pass Advanced Feature IDs via the SDK’s extra_body parameter (Python/TS) or as additional JSON fields in the request body:

# Python — extra_body
response = client.chat.completions.create(
    model="smart/balanced",
    messages=[...],
    extra_body={"guardrail_id": "pii-redact-prod"},
)
// TypeScript — extra_body option
const response = await client.chat.completions.create({
  model: "smart/balanced",
  messages: [...],
  // @ts-ignore — Routero extension
  guardrail_id: "pii-redact-prod",
});

The extra_body / extended fields are stripped by Routero before the request reaches the upstream provider — the provider never sees them.