API Reference

Complete documentation for all AIRouter endpoints

Base URL: http://localhost:3000

Chat Completions

POST/api/v1/chat/completions

Create a chat completion with intelligent routing

Request Body:

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "user",
      "content": "Hello, world!"
    }
  ],
  "temperature": 0.7,
  "routingStrategy": "cost",
  "enableCache": true
}

Response:

{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-3.5-turbo",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "Hello! How can I help you today?"
    },
    "finishReason": "stop"
  }],
  "usage": {
    "promptTokens": 10,
    "completionTokens": 9,
    "totalTokens": 19
  },
  "provider": "openai",
  "cost": 28,
  "cached": false
}

Authentication

All API requests require an API key in the Authorization header:

Authorization: Bearer sk-air-your-api-key

Key Parameters

ParameterTypeDescription
modelstringModel name (e.g., "gpt-3.5-turbo")
messagesarrayArray of message objects
routingStrategystringcost, latency, priority, fallback
enableCachebooleanEnable response caching (default: true)
temperaturenumber0-2, controls randomness

Error Codes

CodeMeaning
200Success
400Bad Request - Invalid parameters
401Unauthorized - Invalid API key
402Payment Required - Insufficient credits
429Rate Limited - Too many requests
503Service Unavailable - No providers available

Try the Interactive API

Want to test the API directly in your browser? Check out our Swagger UI with live examples.

Open Interactive API Docs →