{
  "openapi": "3.1.0",
  "info": {
    "title": "TexAPI",
    "version": "2.0.0",
    "description": "TexAPI API gateway — one key for every model on sale, over OpenAI Chat Completions, OpenAI Responses, Anthropic Messages and Google Gemini formats.\n\n## Authentication\n\nAll API requests require an API key passed in the `Authorization` header:\n\n```\nAuthorization: Bearer sk-texapi-...\n```\n\n## Base URL\n\n```\nhttps://api.texapi.dev\n```\n",
    "contact": {
      "name": "TexAPI Support",
      "url": "https://texapi.dev"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://api.texapi.dev",
      "description": "Production server"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Chat",
      "description": "OpenAI-compatible chat completions"
    },
    {
      "name": "Messages",
      "description": "Anthropic-compatible messages API"
    },
    {
      "name": "Responses",
      "description": "OpenAI Responses API"
    },
    {
      "name": "Gemini",
      "description": "Google Gemini API"
    },
    {
      "name": "Images",
      "description": "Image generation and editing"
    },
    {
      "name": "Models",
      "description": "List and retrieve model information"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "API key with `sk-texapi-` prefix"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_request",
                  "authentication_failed",
                  "rate_limit_exceeded",
                  "insufficient_funds",
                  "unsupported_streaming",
                  "model_not_found",
                  "upstream_error",
                  "internal_error"
                ]
              },
              "message": {
                "type": "string",
                "description": "Human-readable error message"
              }
            }
          }
        }
      },
      "ChatMessage": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": {
            "type": "string",
            "enum": ["system", "user", "assistant", "tool"]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            ]
          },
          "name": {
            "type": "string"
          },
          "tool_calls": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "tool_call_id": {
            "type": "string"
          }
        }
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {
            "type": "string",
            "description": "Model ID (e.g., `deepseek-v4-pro`)"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000000
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2
          },
          "top_p": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "n": {
            "type": "integer",
            "minimum": 1,
            "default": 1
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "stop": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "presence_penalty": {
            "type": "number",
            "minimum": -2,
            "maximum": 2
          },
          "frequency_penalty": {
            "type": "number",
            "minimum": -2,
            "maximum": 2
          },
          "logit_bias": {
            "type": "object",
            "additionalProperties": {
              "type": "number"
            }
          },
          "user": {
            "type": "string"
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object"
              }
            ]
          },
          "response_format": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": ["text", "json_object", "json_schema"]
              }
            }
          },
          "seed": {
            "type": "integer"
          },
          "logprobs": {
            "type": "boolean"
          }
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "required": ["id", "object", "created", "model", "choices"],
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "enum": ["chat.completion"]
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["index", "message", "finish_reason"],
              "properties": {
                "index": {
                  "type": "integer"
                },
                "message": {
                  "$ref": "#/components/schemas/ChatMessage"
                },
                "finish_reason": {
                  "type": "string",
                  "enum": ["stop", "length", "tool_calls", "content_filter"]
                },
                "logprobs": {
                  "type": "object",
                  "nullable": true
                }
              }
            }
          },
          "usage": {
            "type": "object",
            "required": ["prompt_tokens", "completion_tokens", "total_tokens"],
            "properties": {
              "prompt_tokens": {
                "type": "integer"
              },
              "completion_tokens": {
                "type": "integer"
              },
              "total_tokens": {
                "type": "integer"
              },
              "cached_tokens": {
                "type": "integer"
              },
              "cache_creation_tokens": {
                "type": "integer"
              },
              "cost_usd": {
                "type": "number",
                "format": "double",
                "description": "Canonical settled USD amount charged for this request, rounded up to micro-USD before any credit conversion. Retained for backwards compatibility and billing reconciliation on non-streaming JSON responses."
              },
              "cost_credits": {
                "type": "number",
                "format": "double",
                "description": "Additive display amount for settled non-streaming JSON responses, derived after settlement as cost_usd × 100 at the fixed rate 100 credits = 1 USD. Canonical accounting and reconciliation remain in cost_usd; 1 micro-USD = 0.0001 credit."
              }
            }
          },
          "texapi": {
            "$ref": "#/components/schemas/TexapiMetadata"
          }
        }
      },
      "TexapiCost": {
        "type": "object",
        "description": "Settled TexAPI request cost. Streaming SSE responses cannot include a final settled cost before the stream closes; query usage logs for that charge.",
        "properties": {
          "cost_usd": {
            "type": "number",
            "format": "double",
            "description": "Canonical USD amount charged for billing and reconciliation."
          },
          "cost_credits": {
            "type": "number",
            "format": "double",
            "description": "Additive display amount derived as cost_usd × 100 after settlement."
          }
        }
      },
      "TexapiMetadata": {
        "type": "object",
        "properties": {
          "request_id": { "type": "string" },
          "gateway_latency_ms": { "type": "number" },
          "total_latency_ms": { "type": "number" },
          "credits_per_usd": {
            "type": "number",
            "const": 100,
            "description": "Fixed display conversion rate."
          }
        }
      },
      "AnthropicMessage": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": {
            "type": "string",
            "enum": ["user", "assistant"]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            ]
          }
        }
      },
      "AnthropicMessagesRequest": {
        "type": "object",
        "required": ["model", "messages", "max_tokens"],
        "properties": {
          "model": {
            "type": "string"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AnthropicMessage"
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000000
          },
          "system": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            ]
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "top_p": {
            "type": "number"
          },
          "top_k": {
            "type": "integer"
          },
          "stop_sequences": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "tool_choice": {
            "type": "object"
          },
          "metadata": {
            "type": "object"
          }
        }
      },
      "AnthropicMessagesResponse": {
        "type": "object",
        "required": ["id", "type", "role", "content", "model", "stop_reason", "usage"],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": ["message"]
          },
          "role": {
            "type": "string",
            "enum": ["assistant"]
          },
          "content": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "model": {
            "type": "string"
          },
          "stop_reason": {
            "type": "string",
            "enum": ["end_turn", "max_tokens", "stop_sequence", "tool_use"],
            "nullable": true
          },
          "stop_sequence": {
            "type": "string",
            "nullable": true
          },
          "usage": {
            "type": "object",
            "required": ["input_tokens", "output_tokens"],
            "properties": {
              "input_tokens": {
                "type": "integer"
              },
              "output_tokens": {
                "type": "integer"
              },
              "cache_creation_input_tokens": {
                "type": "integer"
              },
              "cache_read_input_tokens": {
                "type": "integer"
              },
              "cost_usd": {
                "type": "number",
                "format": "double",
                "description": "Canonical USD amount charged for this non-streaming request."
              },
              "cost_credits": {
                "type": "number",
                "format": "double",
                "description": "Display credits derived after settlement as cost_usd × 100."
              }
            }
          },
          "texapi": {
            "$ref": "#/components/schemas/TexapiMetadata"
          }
        }
      },
      "Model": {
        "type": "object",
        "required": ["id", "display_name", "family", "endpoint_types", "pricing"],
        "properties": {
          "id": {
            "type": "string",
            "description": "Model identifier"
          },
          "display_name": {
            "type": "string",
            "description": "Human-readable model name"
          },
          "family": {
            "type": "string",
            "description": "Model family (e.g., `deepseek`, `qwen`, `glm`)"
          },
          "endpoint_types": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["chat", "messages", "responses", "generateContent"]
            },
            "description": "Supported API formats"
          },
          "pricing": {
            "type": "object",
            "required": ["input", "output"],
            "properties": {
              "input": {
                "type": "number",
                "format": "double",
                "description": "Price per 1M input tokens (USD)"
              },
              "output": {
                "type": "number",
                "format": "double",
                "description": "Price per 1M output tokens (USD)"
              },
              "cached_input": {
                "type": "number",
                "format": "double",
                "description": "Price per 1M cached input tokens (USD)"
              },
              "per_image": {
                "type": "number",
                "format": "double",
                "description": "Price per image (USD)"
              }
            }
          },
          "pricing_type": {
            "type": "string",
            "enum": ["token", "image", "token_image"]
          }
        }
      },
      "ModelsListResponse": {
        "type": "object",
        "required": ["object", "models"],
        "properties": {
          "object": {
            "type": "string",
            "enum": ["list"]
          },
          "models": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Model"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "tags": ["Chat"],
        "summary": "Create chat completion",
        "description": "OpenAI-compatible chat completions endpoint. Supports streaming and non-streaming responses.\n\nModels that advertise `endpoint_types: [\"chat\"]` are accessible via this endpoint.\n",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Server-sent events stream"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient funds",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Upstream error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "tags": ["Messages"],
        "summary": "Create message (Anthropic format)",
        "description": "Anthropic-compatible messages endpoint. Supports streaming via SSE.\n\nModels that advertise `endpoint_types: [\"messages\"]` are accessible via this endpoint.\n",
        "operationId": "createMessage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnthropicMessagesRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicMessagesResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient funds",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/responses": {
      "post": {
        "tags": ["Responses"],
        "summary": "Create response (OpenAI Responses format)",
        "description": "OpenAI Responses API format",
        "operationId": "createResponse",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model"],
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "input": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array"
                      }
                    ]
                  },
                  "messages": {
                    "type": "array"
                  },
                  "stream": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "usage": { "$ref": "#/components/schemas/TexapiCost" },
                    "texapi": { "$ref": "#/components/schemas/TexapiMetadata" }
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "tags": ["Models"],
        "summary": "List available models",
        "description": "Returns a list of all available models with their pricing and capabilities.\n\nThis endpoint does not require authentication.\n",
        "operationId": "listModels",
        "security": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelsListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/images/generations": {
      "post": {
        "tags": ["Images"],
        "summary": "Generate image",
        "description": "Generate images from text prompts",
        "operationId": "createImageGeneration",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "prompt"],
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "Image model ID"
                  },
                  "prompt": {
                    "type": "string",
                    "description": "Text description of the image"
                  },
                  "n": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1,
                    "default": 1,
                    "description": "Number of images (currently only 1 supported)"
                  },
                  "size": {
                    "type": "string",
                    "description": "Image dimensions"
                  },
                  "quality": {
                    "type": "string",
                    "enum": ["standard", "hd"]
                  },
                  "style": {
                    "type": "string"
                  },
                  "response_format": {
                    "type": "string",
                    "enum": ["url", "b64_json"]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["created", "data"],
                  "properties": {
                    "created": {
                      "type": "integer"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "url": {
                            "type": "string"
                          },
                          "b64_json": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "usage": { "$ref": "#/components/schemas/TexapiCost" },
                    "texapi": { "$ref": "#/components/schemas/TexapiMetadata" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/images/edits": {
      "post": {
        "tags": ["Images"],
        "summary": "Edit image",
        "description": "Modify images using prompts",
        "operationId": "createImageEdit",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["model", "image", "prompt"],
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "image": {
                    "type": "string",
                    "format": "binary"
                  },
                  "mask": {
                    "type": "string",
                    "format": "binary"
                  },
                  "prompt": {
                    "type": "string"
                  },
                  "n": {
                    "type": "integer"
                  },
                  "size": {
                    "type": "string"
                  },
                  "response_format": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "usage": { "$ref": "#/components/schemas/TexapiCost" },
                    "texapi": { "$ref": "#/components/schemas/TexapiMetadata" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1beta/models/{model}:generateContent": {
      "post": {
        "tags": ["Gemini"],
        "summary": "Generate content (Gemini format)",
        "description": "Google Gemini API format for content generation",
        "operationId": "geminiGenerateContent",
        "parameters": [
          {
            "name": "model",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Model path (e.g., `qwen3.8-max`)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "contents": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "generationConfig": {
                    "type": "object"
                  },
                  "safetySettings": {
                    "type": "array"
                  },
                  "tools": {
                    "type": "array"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "usage": { "$ref": "#/components/schemas/TexapiCost" },
                    "texapi": { "$ref": "#/components/schemas/TexapiMetadata" }
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1beta/models/{model}:streamGenerateContent": {
      "post": {
        "tags": ["Gemini"],
        "summary": "Stream generate content (Gemini format)",
        "description": "Streaming variant of Gemini content generation",
        "operationId": "geminiStreamGenerateContent",
        "parameters": [
          {
            "name": "model",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
