{
  "openapi": "3.1.0",
  "info": {
    "title": "AIRouter OpenAI-compatible API",
    "description": "AIRouter provides an OpenAI-compatible LLM API with a RUB balance, public model catalog, API keys and setup instructions for SDKs, backend services and AI agents.",
    "version": "2026-05-08"
  },
  "servers": [
    {
      "url": "https://ai-router.app",
      "description": "AIRouter production"
    }
  ],
  "tags": [
    {
      "name": "Models"
    },
    {
      "name": "Chat Completions"
    },
    {
      "name": "Anthropic Messages"
    }
  ],
  "paths": {
    "/api/v1/models": {
      "get": {
        "tags": ["Models"],
        "summary": "List public AIRouter models",
        "description": "Returns active public model ids and pricing metadata for the AIRouter catalog.",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "Public model catalog",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                },
                "examples": {
                  "catalog": {
                    "summary": "Public model catalog item",
                    "value": {
                      "object": "list",
                      "data": [
                        {
                          "id": "deepseek/deepseek-v4-flash",
                          "object": "model",
                          "created": 1776990236,
                          "owned_by": "deepseek",
                          "display_name": "DeepSeek: DeepSeek V4 Flash",
                          "context_length": 1048576,
                          "max_context_tokens": 1048576,
                          "pricing": {
                            "input_per_1m_rub": "11.00",
                            "output_per_1m_rub": "22.00"
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/chat/completions": {
      "post": {
        "tags": ["Chat Completions"],
        "summary": "Create an OpenAI-compatible chat completion",
        "description": "OpenAI-compatible Chat Completions endpoint. Start with non-streaming text requests and an explicit max_tokens value.",
        "operationId": "createChatCompletion",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              },
              "examples": {
                "simple": {
                  "summary": "Simple non-streaming request",
                  "value": {
                    "model": "<AIROUTER_MODEL>",
                    "messages": [
                      {
                        "role": "user",
                        "content": "Проверь подключение и ответь коротко"
                      }
                    ],
                    "max_tokens": 64,
                    "stream": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion response or server-sent event stream when stream=true",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "tags": ["Anthropic Messages"],
        "summary": "Create an Anthropic Messages response",
        "description": "Anthropic-native Messages endpoint for Claude Code-style clients. Use root ANTHROPIC_BASE_URL=https://ai-router.app. For Claude Code, set ANTHROPIC_MODEL=sonnet plus AIRouter catalog ids in ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL. AIRouter keeps auth, model allowlist, billing preflight and usage logging while accepting native fields such as tools, tool_choice, thinking, cache_control and multimodal content blocks when the selected model supports them.",
        "operationId": "createAnthropicMessage",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnthropicMessagesRequest"
              },
              "examples": {
                "simple": {
                  "summary": "Simple Claude Code-style request",
                  "value": {
                    "model": "<AIROUTER_MODEL>",
                    "messages": [
                      {
                        "role": "user",
                        "content": "Проверь подключение и ответь коротко"
                      }
                    ],
                    "max_tokens": 64,
                    "stream": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Anthropic-style response or SSE stream",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicMessagesResponse"
                },
                "examples": {
                  "simple": {
                    "summary": "Simple text response",
                    "value": {
                      "id": "msg_airouter_example",
                      "type": "message",
                      "role": "assistant",
                      "content": [
                        {
                          "type": "text",
                          "text": "Подключение работает."
                        }
                      ],
                      "model": "<AIROUTER_MODEL>",
                      "stop_reason": "end_turn",
                      "usage": {
                        "input_tokens": 16,
                        "output_tokens": 5
                      }
                    }
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/AnthropicError"
          },
          "401": {
            "$ref": "#/components/responses/AnthropicError"
          },
          "402": {
            "$ref": "#/components/responses/AnthropicError"
          },
          "403": {
            "$ref": "#/components/responses/AnthropicError"
          },
          "404": {
            "$ref": "#/components/responses/AnthropicError"
          },
          "500": {
            "$ref": "#/components/responses/AnthropicError"
          },
          "502": {
            "$ref": "#/components/responses/AnthropicError"
          },
          "504": {
            "$ref": "#/components/responses/AnthropicError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key"
      }
    },
    "responses": {
      "Error": {
        "description": "AIRouter API error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "AnthropicError": {
        "description": "Anthropic-style AIRouter API error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "ModelList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": ["list"],
            "examples": ["list"]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Model"
            }
          }
        },
        "required": ["object", "data"]
      },
      "Model": {
        "type": "object",
        "description": "Public-safe AIRouter model record. Use id as the exact model value in chat/completions requests.",
        "properties": {
          "id": {
            "type": "string",
            "examples": ["deepseek/deepseek-v4-flash"]
          },
          "object": {
            "type": "string",
            "enum": ["model"],
            "examples": ["model"]
          },
          "created": {
            "type": "integer",
            "format": "int64",
            "description": "Unix timestamp for OpenAI-compatible model shape."
          },
          "display_name": {
            "type": "string",
            "nullable": true,
            "examples": ["DeepSeek V4 Flash"]
          },
          "owned_by": {
            "type": "string"
          },
          "context_length": {
            "type": "integer",
            "nullable": true
          },
          "max_context_tokens": {
            "type": "integer",
            "nullable": true
          },
          "pricing": {
            "$ref": "#/components/schemas/ModelPricing"
          },
          "input_per_1m_rub": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              }
            ],
            "nullable": true
          },
          "output_per_1m_rub": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              }
            ],
            "nullable": true
          }
        },
        "required": ["id", "object", "created", "owned_by", "pricing"]
      },
      "ModelPricing": {
        "type": "object",
        "properties": {
          "input_per_1m_rub": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              }
            ],
            "nullable": true,
            "examples": ["11.00"]
          },
          "output_per_1m_rub": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              }
            ],
            "nullable": true,
            "examples": ["22.00"]
          }
        }
      },
      "ChatCompletionRequest": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "examples": ["<AIROUTER_MODEL>"]
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "stream": {
            "type": "boolean",
            "default": false
          }
        },
        "required": ["model", "messages"]
      },
      "ChatMessage": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": ["system", "user", "assistant", "tool"]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            ]
          }
        },
        "required": ["role", "content"]
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "usage": {
            "type": "object"
          }
        }
      },
      "AnthropicMessagesRequest": {
        "type": "object",
        "description": "Anthropic Messages-compatible request handled by AIRouter with AIRouter auth, model and billing controls. Native extension fields are accepted; verify tools, thinking and multimodal workflows on the chosen model before production use.",
        "additionalProperties": true,
        "properties": {
          "model": {
            "type": "string",
            "examples": ["<AIROUTER_MODEL>"]
          },
          "models": {
            "type": "array",
            "description": "Optional Anthropic Messages model preference list. AIRouter still applies model allowlist and billing controls before handling the request.",
            "items": {
              "type": "string"
            }
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AnthropicMessage"
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number"
          },
          "top_p": {
            "type": "number"
          },
          "stop_sequences": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "system": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            ]
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "additionalProperties": true
              }
            ]
          },
          "thinking": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": ["model", "messages", "max_tokens"]
      },
      "AnthropicMessage": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "role": {
            "type": "string",
            "enum": ["user", "assistant"]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            ]
          }
        },
        "required": ["role", "content"]
      },
      "AnthropicMessagesResponse": {
        "type": "object",
        "description": "Anthropic-style response from AIRouter. Extra response fields may be present when supported by the selected model.",
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "role": {
            "type": "string"
          },
          "content": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "properties": {
                "type": {
                  "type": "string",
                  "examples": ["text"]
                },
                "text": {
                  "type": "string"
                },
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "input": {
                  "type": "object",
                  "additionalProperties": true
                },
                "tool_use_id": {
                  "type": "string"
                },
                "content": {
                  "oneOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    {
                      "type": "object",
                      "additionalProperties": true
                    }
                  ]
                }
              }
            }
          },
          "model": {
            "type": "string"
          },
          "stop_reason": {
            "type": "string",
            "nullable": true
          },
          "stop_sequence": {
            "type": "string",
            "nullable": true
          },
          "usage": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "input_tokens": {
                "type": "integer"
              },
              "output_tokens": {
                "type": "integer"
              },
              "total_tokens": {
                "type": "integer"
              }
            }
          }
        }
      },
      "AnthropicErrorResponse": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": ["error"]
          },
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "examples": ["invalid_request_error", "authentication_error", "billing_error", "api_error"]
              },
              "message": {
                "type": "string"
              }
            },
            "required": ["type", "message"]
          }
        },
        "required": ["type", "error"]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "examples": ["invalid_api_key", "insufficient_balance", "model_not_found"]
              },
              "message": {
                "type": "string"
              },
              "code": {
                "type": "integer"
              }
            },
            "required": ["type", "message"]
          }
        },
        "required": ["error"]
      }
    }
  }
}
