{
  "openapi": "3.1.0",
  "info": {
    "title": "TodAPI — OpenAI-compatible LLM gateway",
    "version": "1.0.0",
    "description": "TodAPI routes OpenAI-compatible requests to Claude, GPT, Gemini, DeepSeek, GLM, Qwen and Kimi models through one endpoint and one prepaid USD balance. Billing is per token; there is no subscription, no minimum spend and credits do not expire. TodAPI is an independent gateway and is not affiliated with any model vendor.",
    "contact": { "email": "support@todapi.work", "url": "https://todapi.work/" },
    "license": { "name": "Proprietary" }
  },
  "servers": [{ "url": "https://todapi.work/v1", "description": "Production" }],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "API key from the console, sent as `Authorization: Bearer <key>`." }
    },
    "schemas": {
      "Message": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": { "type": "string", "enum": ["system", "user", "assistant", "tool"] },
          "content": { "type": "string" }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": { "type": "integer" },
          "completion_tokens": { "type": "integer" },
          "total_tokens": { "type": "integer" }
        }
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string" },
          "created": { "type": "integer" },
          "model": { "type": "string" },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": { "type": "integer" },
                "message": { "$ref": "#/components/schemas/Message" },
                "finish_reason": { "type": "string" }
              }
            }
          },
          "usage": { "$ref": "#/components/schemas/Usage" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": { "type": "string" },
              "code": { "type": "string" },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/models": {
      "get": {
        "summary": "List models available to this key",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "Model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": { "type": "string" },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "string" },
                          "object": { "type": "string" },
                          "owned_by": { "type": "string" }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "description": "Invalid or missing key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "summary": "OpenAI-compatible chat completion (streaming supported)",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "messages"],
                "properties": {
                  "model": { "type": "string", "examples": ["deepseek-v4.1-flash", "gpt-6-luna", "claude-sonnet-5-5"] },
                  "messages": { "type": "array", "items": { "$ref": "#/components/schemas/Message" } },
                  "stream": { "type": "boolean", "description": "When true the response is text/event-stream, ending with `data: [DONE]`." },
                  "temperature": { "type": "number" },
                  "max_tokens": { "type": "integer" },
                  "tools": { "type": "array", "items": { "type": "object" } }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion, or an SSE stream when `stream` is true",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChatCompletion" } } }
          },
          "401": { "description": "Invalid key" },
          "402": { "description": "Prepaid balance exhausted — not retryable" },
          "429": { "description": "Rate or concurrency limit — retry with backoff" },
          "5xx": { "description": "All routes for the model failed" }
        }
      }
    },
    "/messages": {
      "post": {
        "summary": "Anthropic-shaped messages endpoint",
        "operationId": "createMessage",
        "description": "Accepts the Anthropic messages request shape for Claude-style clients. Same key as the OpenAI-shaped endpoint.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "messages", "max_tokens"],
                "properties": {
                  "model": { "type": "string" },
                  "messages": { "type": "array", "items": { "$ref": "#/components/schemas/Message" } },
                  "max_tokens": { "type": "integer" },
                  "stream": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Message response" } }
      }
    },
    "/usage": {
      "get": {
        "summary": "Token usage for the authenticated key",
        "operationId": "getUsage",
        "responses": { "200": { "description": "Aggregated usage" } }
      }
    }
  }
}
