{
  "openapi": "3.1.0",
  "info": {
    "title": "Anyhost Model API",
    "version": "1.0.0",
    "description": "Model inference for applications deployed on Anyhost. Model input and output are not stored by the Model API."
  },
  "servers": [
    { "url": "https://models.anyhostcloud.com/v1", "description": "Production" },
    { "url": "https://models.testing.anyhostcloud.com/v1", "description": "Testing" }
  ],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List published Catalog models",
        "responses": {
          "200": {
            "description": "Catalog projection",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ModelList" } } }
          },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Create a Chat Completion Generation",
        "description": "Supports JSON and server-sent events. One request creates one Generation and is never automatically retried by Anyhost.",
        "parameters": [{ "$ref": "#/components/parameters/AnthropicBeta" }],
        "requestBody": { "$ref": "#/components/requestBodies/Inference" },
        "responses": {
          "200": { "$ref": "#/components/responses/Inference" },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "402": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "410": { "$ref": "#/components/responses/Error" },
          "413": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "502": { "$ref": "#/components/responses/Error" },
          "503": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/responses": {
      "post": {
        "operationId": "createResponse",
        "summary": "Create a Responses Generation",
        "description": "Supports JSON and server-sent events. One request creates one Generation and is never automatically retried by Anyhost.",
        "parameters": [{ "$ref": "#/components/parameters/AnthropicBeta" }],
        "requestBody": { "$ref": "#/components/requestBodies/Inference" },
        "responses": {
          "200": { "$ref": "#/components/responses/Inference" },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "402": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "410": { "$ref": "#/components/responses/Error" },
          "413": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "502": { "$ref": "#/components/responses/Error" },
          "503": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/messages": {
      "post": {
        "operationId": "createMessage",
        "summary": "Create a Messages Generation",
        "description": "Uses Bearer authentication and does not require an anthropic-version header. Supports JSON and server-sent events.",
        "parameters": [{ "$ref": "#/components/parameters/AnthropicBeta" }],
        "requestBody": { "$ref": "#/components/requestBodies/Inference" },
        "responses": {
          "200": { "$ref": "#/components/responses/Inference" },
          "400": { "$ref": "#/components/responses/MessagesError" },
          "401": { "$ref": "#/components/responses/MessagesError" },
          "402": { "$ref": "#/components/responses/MessagesError" },
          "403": { "$ref": "#/components/responses/MessagesError" },
          "410": { "$ref": "#/components/responses/MessagesError" },
          "413": { "$ref": "#/components/responses/MessagesError" },
          "429": { "$ref": "#/components/responses/MessagesError" },
          "502": { "$ref": "#/components/responses/MessagesError" },
          "503": { "$ref": "#/components/responses/MessagesError" }
        }
      }
    },
    "/generation/{generation_id}": {
      "get": {
        "operationId": "getGeneration",
        "summary": "Get content-free usage and settlement state",
        "parameters": [{ "name": "generation_id", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^gen_" } }],
        "responses": {
          "200": { "description": "Generation", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Generation" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "Anyhost Model Runtime Key" }
    },
    "parameters": {
      "AnthropicBeta": {
        "name": "x-anthropic-beta",
        "in": "header",
        "required": false,
        "schema": { "type": "string" },
        "description": "A released beta capability value supported by the selected Catalog model."
      }
    },
    "requestBodies": {
      "Inference": {
        "required": true,
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/InferenceRequest" }
          }
        }
      }
    },
    "responses": {
      "Inference": {
        "description": "Protocol-shaped response. The x-anyhost-generation-id header is present after admission.",
        "headers": {
          "x-anyhost-generation-id": { "required": true, "schema": { "type": "string" } }
        },
        "content": {
          "application/json": { "schema": { "$ref": "#/components/schemas/InferenceResponse" } },
          "text/event-stream": { "schema": { "type": "string" } }
        }
      },
      "Error": {
        "description": "Safe Anyhost error",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "MessagesError": {
        "description": "Safe Messages-shaped Anyhost error",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MessagesError" } } }
      }
    },
    "schemas": {
      "InferenceRequest": {
        "type": "object",
        "required": ["model"],
        "properties": {
          "model": { "type": "string", "description": "Exact model ID returned by the Anyhost Catalog; IDs and display names follow the published model identity." },
          "stream": { "type": "boolean", "default": false }
        },
        "additionalProperties": true,
        "description": "The remaining properties follow the selected released protocol and Catalog capabilities. Caller-selected provider, route, fallback, debug, plugin, alternate-model, private observability, background, and stored-response controls are not supported. The store field is accepted only as false."
      },
      "InferenceResponse": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "description": "Anyhost Generation ID" },
          "model": { "type": "string", "description": "Requested Catalog Model ID" },
          "usage": { "$ref": "#/components/schemas/Usage" }
        },
        "additionalProperties": true
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": { "type": "integer", "minimum": 0 },
          "completion_tokens": { "type": "integer", "minimum": 0 },
          "input_tokens": { "type": "integer", "minimum": 0 },
          "output_tokens": { "type": "integer", "minimum": 0 },
          "cost": { "type": ["string", "null"], "description": "Final customer USD list-price charge" },
          "credits": { "type": ["string", "null"], "description": "Final Model Credit debit" },
          "settlement_status": { "type": "string", "enum": ["pending", "settled"] }
        },
        "additionalProperties": true
      },
      "Model": {
        "type": "object",
        "required": ["id", "object", "display_name", "lifecycle_status", "protocols", "capabilities"],
        "properties": {
          "id": { "type": "string", "description": "Callable model ID aligned with the published model identity." },
          "object": { "const": "model" },
          "display_name": { "type": "string", "description": "Human-readable developer and model name." },
          "lifecycle_status": { "type": "string", "enum": ["active", "deprecated", "suspended"] },
          "protocols": { "type": "array", "items": { "type": "string", "enum": ["chat_completions", "responses", "messages"] } },
          "capabilities": { "type": "object", "additionalProperties": true },
          "context_length": { "type": "integer", "minimum": 0 },
          "max_output_tokens": { "type": "integer", "minimum": 0 },
          "customer_prices": {
            "type": "object",
            "description": "Per-meter customer charge ceilings derived from the model pricing policy.",
            "additionalProperties": { "$ref": "#/components/schemas/ModelMeterPrice" }
          },
          "replacement_model_id": { "type": "string" },
          "sunset_at": { "type": "string", "format": "date-time" }
        }
      },
      "ModelMeterPrice": {
        "type": "object",
        "required": ["price", "currency", "unit", "kind"],
        "properties": {
          "price": { "type": "string", "description": "Exact decimal price in the stated currency per unit." },
          "currency": { "const": "USD" },
          "unit": { "type": "string", "enum": ["input_token", "output_token", "cached_input_token", "cache_write_token", "reasoning_token", "request"] },
          "kind": { "const": "ceiling" }
        },
        "additionalProperties": false
      },
      "ModelList": {
        "type": "object",
        "required": ["object", "data"],
        "properties": {
          "object": { "const": "list" },
          "data": { "type": "array", "items": { "$ref": "#/components/schemas/Model" } }
        }
      },
      "Generation": {
        "type": "object",
        "required": ["id", "object", "model", "protocol", "status", "settlement_status", "started_at"],
        "properties": {
          "id": { "type": "string" },
          "object": { "const": "model.generation" },
          "model": { "type": "string" },
          "protocol": { "type": "string" },
          "status": { "type": "string", "enum": ["running", "succeeded", "failed"] },
          "settlement_status": { "type": "string", "enum": ["pending", "settled", "absorbed"] },
          "input_tokens": { "type": "integer", "minimum": 0 },
          "output_tokens": { "type": "integer", "minimum": 0 },
          "cache_read_tokens": { "type": "integer", "minimum": 0 },
          "cache_write_tokens": { "type": "integer", "minimum": 0 },
          "reasoning_tokens": { "type": "integer", "minimum": 0 },
          "cost": { "type": ["string", "null"] },
          "credits": { "type": ["string", "null"] },
          "pricing_policy_version": { "type": "string" },
          "adjustments": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/GenerationAdjustment" }
          },
          "error_code": { "type": "string" },
          "error_message": { "type": "string" },
          "started_at": { "type": "string", "format": "date-time" },
          "completed_at": { "type": "string", "format": "date-time" },
          "settled_at": { "type": "string", "format": "date-time" }
        }
      },
      "GenerationAdjustment": {
        "type": "object",
        "required": ["id", "amount_microcredits", "customer_charge_usd_decimal", "reason", "created_at"],
        "properties": {
          "id": { "type": "string" },
          "amount_microcredits": { "type": "integer", "description": "Signed Model Credit microcredit delta; negative values are refunds" },
          "customer_charge_usd_decimal": { "type": "string", "description": "Corrected total customer charge after this adjustment" },
          "reason": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "ErrorDetail": {
        "type": "object",
        "required": ["type", "code", "message"],
        "properties": {
          "type": { "type": "string" },
          "code": { "type": "string" },
          "message": { "type": "string" },
          "retryable": { "type": "boolean", "description": "Caller guidance; Anyhost never retries inference automatically" }
        }
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": { "error": { "$ref": "#/components/schemas/ErrorDetail" } }
      },
      "MessagesError": {
        "type": "object",
        "required": ["type", "error"],
        "properties": {
          "type": { "const": "error" },
          "error": { "$ref": "#/components/schemas/ErrorDetail" }
        }
      }
    }
  }
}
