{
  "openapi": "3.1.0",
  "info": {
    "title": "OauthRouter API",
    "description": "OpenAI-compatible LLM router. Route requests to Anthropic, OpenAI, Google, Mistral, Groq, xAI, DeepSeek, Together, Cohere, Cloudflare AI, and OpenRouter through a single endpoint using your own API keys or OAuth tokens.",
    "version": "1.0.0",
    "contact": {
      "name": "OauthRouter",
      "url": "https://oauthrouter.com"
    },
    "license": {
      "name": "Proprietary"
    },
    "x-logo": {
      "url": "https://oauthrouter.com/favicon.ico"
    }
  },
  "servers": [
    {
      "url": "https://api.oauthrouter.com/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Chat",
      "description": "Chat completions"
    },
    {
      "name": "Models",
      "description": "Model catalog"
    }
  ],
  "paths": {
    "/chat/completions": {
      "post": {
        "tags": [
          "Chat"
        ],
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "description": "OpenAI-compatible chat completion endpoint. Routes to the configured provider based on the model name.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              },
              "examples": {
                "claude": {
                  "summary": "Anthropic Claude",
                  "value": {
                    "model": "anthropic/claude-sonnet-4-5",
                    "messages": [
                      {
                        "role": "user",
                        "content": "Hello!"
                      }
                    ],
                    "max_tokens": 1024
                  }
                },
                "gpt": {
                  "summary": "OpenAI GPT-4o",
                  "value": {
                    "model": "openai/gpt-4o",
                    "messages": [
                      {
                        "role": "user",
                        "content": "Hello!"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit or monthly budget exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Upstream provider error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/models": {
      "get": {
        "tags": [
          "Models"
        ],
        "operationId": "listModels",
        "summary": "List available models",
        "description": "Returns models available to the caller. Authenticated requests receive models from their configured providers only. Unauthenticated requests receive a generic catalog.",
        "responses": {
          "200": {
            "description": "Model list",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "lr_live_xxx",
        "description": "API token from https://oauthrouter.com/dashboard/api. Format: lr_live_ followed by 48 hex characters."
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "Model identifier. Format: provider/model-name (e.g. anthropic/claude-sonnet-4-5) or plain model-name.",
            "example": "anthropic/claude-sonnet-4-5"
          },
          "messages": {
            "type": "array",
            "description": "Array of message objects.",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "max_tokens": {
            "type": "integer",
            "default": 8192,
            "description": "Maximum tokens to generate."
          },
          "temperature": {
            "type": "number",
            "default": 1,
            "minimum": 0,
            "maximum": 2,
            "description": "Sampling temperature."
          },
          "top_p": {
            "type": "number",
            "default": 1,
            "minimum": 0,
            "maximum": 1,
            "description": "Nucleus sampling threshold."
          },
          "stream": {
            "type": "boolean",
            "default": false,
            "description": "If true, streams partial progress as server-sent events."
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant"
            ]
          },
          "content": {
            "type": "string",
            "description": "Message text content."
          }
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "enum": [
              "chat.completion"
            ]
          },
          "created": {
            "type": "integer",
            "description": "Unix timestamp."
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "message": {
                  "$ref": "#/components/schemas/Message"
                },
                "finish_reason": {
                  "type": "string",
                  "enum": [
                    "stop",
                    "length",
                    "content_filter",
                    "tool_calls"
                  ]
                }
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {
                "type": "integer"
              },
              "completion_tokens": {
                "type": "integer"
              },
              "total_tokens": {
                "type": "integer"
              }
            }
          }
        }
      },
      "ModelList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "example": "anthropic/claude-sonnet-4-5"
                },
                "name": {
                  "type": "string"
                },
                "context_length": {
                  "type": "integer"
                },
                "pricing": {
                  "type": "object",
                  "properties": {
                    "prompt": {
                      "type": "string",
                      "description": "USD per 1M input tokens."
                    },
                    "completion": {
                      "type": "string",
                      "description": "USD per 1M output tokens."
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "authentication_error",
                  "invalid_request_error",
                  "rate_limit_error",
                  "api_error"
                ]
              },
              "docs_url": {
                "type": "string",
                "description": "URL to the error documentation."
              }
            }
          }
        }
      }
    }
  }
}