{
  "openapi": "3.1.0",
  "info": {
    "title": "Token Gear inference API",
    "version": "2026-11-08",
    "summary": "The OpenAI-compatible subset of the Token Gear API, by FreshToken.",
    "description": "OpenAI-compatible chat completions, completions, embeddings, a subset of the Responses API, and the model list. Send an Idempotency-Key with every request: the same key and the same body is a safe retry that is not charged twice; the same key with a different body is 422 idempotency_key_reused; a new request needs a new key. A request without one is answered as a new request each time, and a retry of it is charged again. Changes are dated in the changelog at /docs/changelog."
  },
  "servers": [
    {
      "url": "https://api.freshtoken.ai"
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The answer; with \"stream\": true, server-sent events. A replayed answer carries Idempotent-Replayed: true.",
            "headers": {
              "X-FreshToken-Id": {
                "$ref": "#/components/headers/RequestId"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/IdempotentReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The request is refused before anything is held or sent: a field that is not valid, one the endpoint does not support, a prompt longer than the model’s context, a requirement no provider can meet, a model the customer’s agreement prices below the platform’s minimum margin (agreement_price_below_margin), a request larger than the customer’s capacity order can ever take (capacity_request_too_large), or an Idempotency-Key that is not 1–255 printable ASCII characters. Or, on the unified billing path, the answer is larger than the gateway returns at once (8 MiB by default; response_too_large, its message naming the limit): it is not retried on another provider and the same Idempotency-Key gets the same answer; send embeddings in smaller batches, or ask for a stream or fewer tokens. Codes: invalid_request, unsupported_parameter, context_length_exceeded, no_compliant_provider, response_too_large, agreement_price_below_margin, capacity_request_too_large.",
            "x-freshtoken-error-codes": [
              "invalid_request",
              "unsupported_parameter",
              "context_length_exceeded",
              "no_compliant_provider",
              "response_too_large",
              "agreement_price_below_margin",
              "capacity_request_too_large"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, unknown, revoked or disabled. Codes: invalid_api_key.",
            "x-freshtoken-error-codes": [
              "invalid_api_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Not enough credit, or an account or key budget would be passed: nothing is sent or charged. Codes: insufficient_credits, budget_exceeded, spend_cap_exceeded.",
            "x-freshtoken-error-codes": [
              "insufficient_credits",
              "budget_exceeded",
              "spend_cap_exceeded"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key may not use the model, or its authority was revoked before the request was sent. Codes: model_not_allowed, api_key_authority_revoked.",
            "x-freshtoken-error-codes": [
              "model_not_allowed",
              "api_key_authority_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No model has that catalog id. Codes: model_not_found.",
            "x-freshtoken-error-codes": [
              "model_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "A request with this Idempotency-Key is still running: retry after Retry-After. Codes: idempotency_in_progress.",
            "x-freshtoken-error-codes": [
              "idempotency_in_progress"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "This Idempotency-Key was used with a different body, its answer was too large to keep, or its answer is no longer kept (its request, named in X-FreshToken-Id, is not run again): send a new request with a new key. Codes: idempotency_key_reused, idempotency_response_too_large, idempotency_response_lost.",
            "x-freshtoken-error-codes": [
              "idempotency_key_reused",
              "idempotency_response_too_large",
              "idempotency_response_lost"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "A rate or concurrency limit: retry after Retry-After. Codes: rate_limited.",
            "x-freshtoken-error-codes": [
              "rate_limited"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "The provider failed after the request was sent, and no other could take it; a stream’s error event carries the same code. Codes: upstream_error.",
            "x-freshtoken-error-codes": [
              "upstream_error"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "No provider can serve the model now, or the gateway cannot check what it must before sending. Codes: no_available_provider, service_unavailable.",
            "x-freshtoken-error-codes": [
              "no_available_provider",
              "service_unavailable"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/completions": {
      "post": {
        "operationId": "createCompletion",
        "summary": "Create a text completion (the legacy completions API)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The answer; with \"stream\": true, server-sent events. A replayed answer carries Idempotent-Replayed: true.",
            "headers": {
              "X-FreshToken-Id": {
                "$ref": "#/components/headers/RequestId"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/IdempotentReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Completion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The request is refused before anything is held or sent: a field that is not valid, one the endpoint does not support, a prompt longer than the model’s context, a requirement no provider can meet, a model the customer’s agreement prices below the platform’s minimum margin (agreement_price_below_margin), a request larger than the customer’s capacity order can ever take (capacity_request_too_large), or an Idempotency-Key that is not 1–255 printable ASCII characters. Or, on the unified billing path, the answer is larger than the gateway returns at once (8 MiB by default; response_too_large, its message naming the limit): it is not retried on another provider and the same Idempotency-Key gets the same answer; send embeddings in smaller batches, or ask for a stream or fewer tokens. Codes: invalid_request, unsupported_parameter, context_length_exceeded, no_compliant_provider, response_too_large, agreement_price_below_margin, capacity_request_too_large.",
            "x-freshtoken-error-codes": [
              "invalid_request",
              "unsupported_parameter",
              "context_length_exceeded",
              "no_compliant_provider",
              "response_too_large",
              "agreement_price_below_margin",
              "capacity_request_too_large"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, unknown, revoked or disabled. Codes: invalid_api_key.",
            "x-freshtoken-error-codes": [
              "invalid_api_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Not enough credit, or an account or key budget would be passed: nothing is sent or charged. Codes: insufficient_credits, budget_exceeded, spend_cap_exceeded.",
            "x-freshtoken-error-codes": [
              "insufficient_credits",
              "budget_exceeded",
              "spend_cap_exceeded"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key may not use the model, or its authority was revoked before the request was sent. Codes: model_not_allowed, api_key_authority_revoked.",
            "x-freshtoken-error-codes": [
              "model_not_allowed",
              "api_key_authority_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No model has that catalog id. Codes: model_not_found.",
            "x-freshtoken-error-codes": [
              "model_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "A request with this Idempotency-Key is still running: retry after Retry-After. Codes: idempotency_in_progress.",
            "x-freshtoken-error-codes": [
              "idempotency_in_progress"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "This Idempotency-Key was used with a different body, its answer was too large to keep, or its answer is no longer kept (its request, named in X-FreshToken-Id, is not run again): send a new request with a new key. Codes: idempotency_key_reused, idempotency_response_too_large, idempotency_response_lost.",
            "x-freshtoken-error-codes": [
              "idempotency_key_reused",
              "idempotency_response_too_large",
              "idempotency_response_lost"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "A rate or concurrency limit: retry after Retry-After. Codes: rate_limited.",
            "x-freshtoken-error-codes": [
              "rate_limited"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "The provider failed after the request was sent, and no other could take it; a stream’s error event carries the same code. Codes: upstream_error.",
            "x-freshtoken-error-codes": [
              "upstream_error"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "No provider can serve the model now, or the gateway cannot check what it must before sending. Codes: no_available_provider, service_unavailable.",
            "x-freshtoken-error-codes": [
              "no_available_provider",
              "service_unavailable"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/embeddings": {
      "post": {
        "operationId": "createEmbedding",
        "summary": "Create embeddings",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmbeddingRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The answer. A replayed answer carries Idempotent-Replayed: true.",
            "headers": {
              "X-FreshToken-Id": {
                "$ref": "#/components/headers/RequestId"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/IdempotentReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmbeddingList"
                }
              }
            }
          },
          "400": {
            "description": "The request is refused before anything is held or sent: a field that is not valid, one the endpoint does not support, a prompt longer than the model’s context, a requirement no provider can meet, a model the customer’s agreement prices below the platform’s minimum margin (agreement_price_below_margin), a request larger than the customer’s capacity order can ever take (capacity_request_too_large), or an Idempotency-Key that is not 1–255 printable ASCII characters. Or, on the unified billing path, the answer is larger than the gateway returns at once (8 MiB by default; response_too_large, its message naming the limit): it is not retried on another provider and the same Idempotency-Key gets the same answer; send embeddings in smaller batches, or ask for a stream or fewer tokens. Codes: invalid_request, unsupported_parameter, context_length_exceeded, no_compliant_provider, response_too_large, agreement_price_below_margin, capacity_request_too_large.",
            "x-freshtoken-error-codes": [
              "invalid_request",
              "unsupported_parameter",
              "context_length_exceeded",
              "no_compliant_provider",
              "response_too_large",
              "agreement_price_below_margin",
              "capacity_request_too_large"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, unknown, revoked or disabled. Codes: invalid_api_key.",
            "x-freshtoken-error-codes": [
              "invalid_api_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Not enough credit, or an account or key budget would be passed: nothing is sent or charged. Codes: insufficient_credits, budget_exceeded, spend_cap_exceeded.",
            "x-freshtoken-error-codes": [
              "insufficient_credits",
              "budget_exceeded",
              "spend_cap_exceeded"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key may not use the model, or its authority was revoked before the request was sent. Codes: model_not_allowed, api_key_authority_revoked.",
            "x-freshtoken-error-codes": [
              "model_not_allowed",
              "api_key_authority_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No model has that catalog id. Codes: model_not_found.",
            "x-freshtoken-error-codes": [
              "model_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "A request with this Idempotency-Key is still running: retry after Retry-After. Codes: idempotency_in_progress.",
            "x-freshtoken-error-codes": [
              "idempotency_in_progress"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "This Idempotency-Key was used with a different body, its answer was too large to keep, or its answer is no longer kept (its request, named in X-FreshToken-Id, is not run again): send a new request with a new key. Codes: idempotency_key_reused, idempotency_response_too_large, idempotency_response_lost.",
            "x-freshtoken-error-codes": [
              "idempotency_key_reused",
              "idempotency_response_too_large",
              "idempotency_response_lost"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "A rate or concurrency limit: retry after Retry-After. Codes: rate_limited.",
            "x-freshtoken-error-codes": [
              "rate_limited"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "The provider failed after the request was sent, and no other could take it; a stream’s error event carries the same code. Codes: upstream_error.",
            "x-freshtoken-error-codes": [
              "upstream_error"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "No provider can serve the model now, or the gateway cannot check what it must before sending. Codes: no_available_provider, service_unavailable.",
            "x-freshtoken-error-codes": [
              "no_available_provider",
              "service_unavailable"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/responses": {
      "post": {
        "operationId": "createResponse",
        "summary": "Create a response (a stateless subset of the Responses API)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResponseRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The answer; with \"stream\": true, server-sent events. A replayed answer carries Idempotent-Replayed: true.",
            "headers": {
              "X-FreshToken-Id": {
                "$ref": "#/components/headers/RequestId"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/IdempotentReplayed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Response"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The request is refused before anything is held or sent: a field that is not valid, one the endpoint does not support, a prompt longer than the model’s context, a requirement no provider can meet, a model the customer’s agreement prices below the platform’s minimum margin (agreement_price_below_margin), a request larger than the customer’s capacity order can ever take (capacity_request_too_large), or an Idempotency-Key that is not 1–255 printable ASCII characters. Or, on the unified billing path, the answer is larger than the gateway returns at once (8 MiB by default; response_too_large, its message naming the limit): it is not retried on another provider and the same Idempotency-Key gets the same answer; send embeddings in smaller batches, or ask for a stream or fewer tokens. Codes: invalid_request, unsupported_parameter, context_length_exceeded, no_compliant_provider, response_too_large, agreement_price_below_margin, capacity_request_too_large.",
            "x-freshtoken-error-codes": [
              "invalid_request",
              "unsupported_parameter",
              "context_length_exceeded",
              "no_compliant_provider",
              "response_too_large",
              "agreement_price_below_margin",
              "capacity_request_too_large"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, unknown, revoked or disabled. Codes: invalid_api_key.",
            "x-freshtoken-error-codes": [
              "invalid_api_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Not enough credit, or an account or key budget would be passed: nothing is sent or charged. Codes: insufficient_credits, budget_exceeded, spend_cap_exceeded.",
            "x-freshtoken-error-codes": [
              "insufficient_credits",
              "budget_exceeded",
              "spend_cap_exceeded"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key may not use the model, or its authority was revoked before the request was sent. Codes: model_not_allowed, api_key_authority_revoked.",
            "x-freshtoken-error-codes": [
              "model_not_allowed",
              "api_key_authority_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No model has that catalog id. Codes: model_not_found.",
            "x-freshtoken-error-codes": [
              "model_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "A request with this Idempotency-Key is still running: retry after Retry-After. Codes: idempotency_in_progress.",
            "x-freshtoken-error-codes": [
              "idempotency_in_progress"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "This Idempotency-Key was used with a different body, its answer was too large to keep, or its answer is no longer kept (its request, named in X-FreshToken-Id, is not run again): send a new request with a new key. Codes: idempotency_key_reused, idempotency_response_too_large, idempotency_response_lost.",
            "x-freshtoken-error-codes": [
              "idempotency_key_reused",
              "idempotency_response_too_large",
              "idempotency_response_lost"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "A rate or concurrency limit: retry after Retry-After. Codes: rate_limited.",
            "x-freshtoken-error-codes": [
              "rate_limited"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "The provider failed after the request was sent, and no other could take it; a stream’s error event carries the same code. Codes: upstream_error.",
            "x-freshtoken-error-codes": [
              "upstream_error"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "No provider can serve the model now, or the gateway cannot check what it must before sending. Codes: no_available_provider, service_unavailable.",
            "x-freshtoken-error-codes": [
              "no_available_provider",
              "service_unavailable"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "operationId": "createMessage",
        "summary": "Create a message with Anthropic’s Messages API, served through chat (for clients such as Claude Code)",
        "security": [
          {
            "apiKey": []
          },
          {
            "anthropicApiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "A request in Anthropic’s Messages API; what is sent on, accepted and refused is in the API reference (/docs#messages).",
                "required": [
                  "model",
                  "max_tokens",
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The message; with \"stream\": true, Anthropic’s server-sent events (message_start, content blocks, message_delta, message_stop).",
            "headers": {
              "X-FreshToken-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/count_tokens": {
      "post": {
        "operationId": "countMessageTokens",
        "summary": "Count the input tokens of a Messages API request; only for models whose tokenizer Token Gear has",
        "security": [
          {
            "apiKey": []
          },
          {
            "anthropicApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "A request in Anthropic’s Messages API; what is sent on, accepted and refused is in the API reference (/docs#messages).",
                "required": [
                  "model",
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The count: {\"input_tokens\": N}.",
            "headers": {
              "X-FreshToken-Id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "An error in Anthropic’s shape: {\"type\": \"error\", \"error\": {\"type\", \"message\"}, \"request_id\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "type",
                    "error"
                  ],
                  "properties": {
                    "type": {
                      "const": "error"
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "type",
                        "message"
                      ],
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List the models this key may call, at its prices",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The models, as OpenAI lists them.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                }
              }
            }
          },
          "401": {
            "description": "The API key is missing, unknown, revoked or disabled. Codes: invalid_api_key.",
            "x-freshtoken-error-codes": [
              "invalid_api_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The account policy cannot be read now. Codes: service_unavailable.",
            "x-freshtoken-error-codes": [
              "service_unavailable"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "An API key, sk-…, created in the console."
      },
      "anthropicApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "The same API key in x-api-key, on the Messages API routes only. Sent with a bearer token, the two must be the same key."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "1 to 255 printable ASCII characters (visible characters and the space), a new one for each request and the same one on each retry of it, per account and endpoint. Optional, and recommended: a request without it is answered as a new request each time, so a retry of it runs and is charged again; a key that is not valid is refused 400 invalid_request. A key is bound to its request for good, never released for another body; the request's answer is kept for a retry 24 hours after it completes.",
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255,
          "pattern": "^[\\x20-\\x7E]+$"
        }
      }
    },
    "headers": {
      "RequestId": {
        "description": "The request’s id, as GET /v1/generation looks it up.",
        "schema": {
          "type": "string"
        }
      },
      "IdempotentReplayed": {
        "description": "\"true\" on an answer replayed for a retry with the same Idempotency-Key and body; it called no provider and was not charged again.",
        "schema": {
          "type": "string",
          "enum": [
            "true"
          ]
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "param": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "ChatCompletionRequest": {
        "type": "object",
        "description": "A field not listed here, such as `enable_thinking` or `min_p`, is passed to the model as sent; Claude models refuse one with 400 unsupported_parameter. `audio`, `prediction`, `web_search_options`, `functions`, `function_call`, `cache_salt` and `chat_template` (also inside `chat_template_kwargs`) are refused for every model.",
        "required": [
          "model",
          "messages"
        ],
        "additionalProperties": true,
        "properties": {
          "model": {
            "type": "string",
            "description": "A catalog model id."
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "system",
                    "developer",
                    "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"
                },
                "reasoning_details": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  },
                  "description": "The reasoning blocks an earlier answer returned, sent back as they came on its assistant message, so the model continues from its own thinking. Other fields a message carries are passed to the model as sent."
                }
              }
            },
            "minItems": 1
          },
          "stream": {
            "type": "boolean"
          },
          "stream_options": {
            "type": "object"
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "max_completion_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "temperature": {
            "type": "number"
          },
          "top_p": {
            "type": "number"
          },
          "stop": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object"
              }
            ]
          },
          "parallel_tool_calls": {
            "type": "boolean"
          },
          "response_format": {
            "type": "object"
          },
          "reasoning_effort": {
            "type": "string",
            "description": "How hard a reasoning model thinks. Claude models take `low`, `medium`, `high`, `xhigh` or `max`."
          },
          "top_k": {
            "type": "integer"
          },
          "service_tier": {
            "type": "string"
          },
          "user": {
            "type": "string"
          },
          "thinking": {
            "type": "object",
            "description": "The thinking switch of reasoning models, such as `{\"type\": \"enabled\"}`, passed on as sent. Thinking tokens are billed as output. Claude models take `{\"type\": \"enabled\"}` (thinking as the model decides), `{\"type\": \"adaptive\"}` and their own fields such as `display`; `{\"type\": \"disabled\"}` is not sent to them. Their answer carries the thinking as `reasoning_content` and its signed blocks as `reasoning_details`, to be sent back on the assistant message."
          }
        }
      },
      "ChatCompletion": {
        "type": "object",
        "required": [
          "id",
          "object",
          "model",
          "choices"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "chat.completion"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "CompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string"
          },
          "prompt": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "stream": {
            "type": "boolean"
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "temperature": {
            "type": "number"
          },
          "top_p": {
            "type": "number"
          },
          "stop": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          }
        }
      },
      "Completion": {
        "type": "object",
        "required": [
          "id",
          "object",
          "model",
          "choices"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "text_completion"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "EmbeddingRequest": {
        "type": "object",
        "required": [
          "model",
          "input"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "A model that produces embeddings."
          },
          "input": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "encoding_format": {
            "type": "string",
            "enum": [
              "float",
              "base64"
            ]
          },
          "dimensions": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "EmbeddingList": {
        "type": "object",
        "required": [
          "object",
          "data",
          "model"
        ],
        "properties": {
          "object": {
            "const": "list"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "model": {
            "type": "string"
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "ResponseRequest": {
        "type": "object",
        "required": [
          "model",
          "input"
        ],
        "description": "Stateless: previous_response_id, conversation, stored prompts, background: true, truncation: \"auto\", tools other than functions, file inputs and any field not listed here are refused with 400 unsupported_parameter. store, include, metadata, reasoning.summary, truncation: \"disabled\", background: false and stream_options are accepted and not acted on.",
        "properties": {
          "model": {
            "type": "string"
          },
          "input": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            ]
          },
          "instructions": {
            "type": "string"
          },
          "max_output_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "temperature": {
            "type": "number"
          },
          "top_p": {
            "type": "number"
          },
          "stream": {
            "type": "boolean"
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object"
              }
            ]
          },
          "parallel_tool_calls": {
            "type": "boolean"
          },
          "reasoning": {
            "type": "object"
          },
          "text": {
            "type": "object"
          },
          "service_tier": {
            "type": "string"
          },
          "user": {
            "type": "string"
          },
          "safety_identifier": {
            "type": "string"
          },
          "prompt_cache_key": {
            "type": "string"
          },
          "prompt_cache_retention": {
            "type": "string"
          },
          "top_logprobs": {
            "type": "integer"
          },
          "store": {
            "type": "boolean"
          },
          "include": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "metadata": {
            "type": "object"
          },
          "truncation": {
            "const": "disabled"
          },
          "background": {
            "const": false
          },
          "stream_options": {
            "type": "object"
          }
        }
      },
      "Response": {
        "type": "object",
        "required": [
          "id",
          "object",
          "model",
          "output"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "response"
          },
          "created_at": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "output": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "usage": {
            "type": "object"
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {
            "type": "integer"
          },
          "completion_tokens": {
            "type": "integer"
          },
          "total_tokens": {
            "type": "integer"
          }
        }
      },
      "ModelList": {
        "type": "object",
        "required": [
          "object",
          "data"
        ],
        "properties": {
          "object": {
            "const": "list"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "object"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "object": {
                  "const": "model"
                },
                "owned_by": {
                  "type": "string"
                },
                "context_length": {
                  "type": "integer"
                },
                "api_endpoints": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "pricing": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  }
}