Quickstart

OneRouter provides a unified API that gives you access to hundreds of AI models through a single endpoint, while automatically handling fallbacks and selecting the most cost-effective options. Get started with just a few lines of code using your preferred SDK or framework.

The first step to start using OneRouter is to create an account and get your API key.

After that, feel free to explore our API reference for more details. Or to jump start into our first example below.

Using the OpenAI SDK

from openai import OpenAI

client = OpenAI(
  base_url="https://app.onerouter.pro/v1",
  api_key="<API_KEY>",
)

completion = client.chat.completions.create(
  model="claude-3-5-sonnet@20240620",
  messages=[
    {
      "role": "user",
      "content": "What is the meaning of life?"
    }
  ]
)

print(completion.choices[0].message.content)

Using the OneRouter API directly

import requests
import json

response = requests.post(
  url="https://app.onerouter.pro/v1/chat/completions",
  headers={
    "Authorization": "Bearer <API_KEY>",
    "Content-Type": "application/json"
  },
  data=json.dumps({
    "model": "claude-3-5-sonnet@20240620",  # Optional
    "messages": [
      {
        "role": "user",
        "content": "What is the meaning of life?"
      }
    ]
  })
)
print(response.json()["choices"][0]["message"]["content"])

The API also supports streaming.

Using third-party SDKs

For information about using third-party SDKs and frameworks with OneRouter, please see our frameworks documentation.

Last updated