{
  "openapi": "3.1.0",
  "info": {
    "title": "CloudService API",
    "version": "1.0.0",
    "description": "Public CloudService API contract for model discovery, OpenAI-compatible generation, Anthropic-compatible Messages, token counting, and authenticated usage. Select the server that matches the API key's billing mode.",
    "contact": {
      "name": "CloudService Support",
      "url": "https://dashboard.yourdomain.example/support"
    }
  },
  "externalDocs": {
    "description": "CloudService API reference",
    "url": "https://docs.yourdomain.example/docs/api-reference"
  },
  "servers": [
    {
      "url": "https://api.yourdomain.example",
      "description": "API-credit keys"
    },
    {
      "url": "https://api.yourdomain.example/token",
      "description": "Token-budget keys"
    }
  ],
  "tags": [
    {
      "name": "Models",
      "description": "Model discovery scoped to the supplied API key."
    },
    {
      "name": "OpenAI compatible",
      "description": "OpenAI-compatible generation endpoints."
    },
    {
      "name": "Anthropic compatible",
      "description": "Anthropic-compatible Messages endpoints."
    },
    {
      "name": "Usage",
      "description": "Authenticated key usage and balance."
    }
  ],
  "paths": {
    "/v1/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List available models",
        "description": "Returns the public catalog without a credential. When a valid credential is supplied, the result is filtered to that key's provider scope and entitlements. An invalid supplied credential produces an authentication error rather than an anonymous fallback.",
        "tags": [
          "Models"
        ],
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          },
          {}
        ],
        "responses": {
          "200": {
            "description": "OpenAI-style model list.",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/OpenAIAuthenticationError"
          },
          "429": {
            "$ref": "#/components/responses/OpenAIRateLimitError"
          },
          "503": {
            "$ref": "#/components/responses/OpenAIServiceUnavailable"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "description": "Creates an OpenAI-compatible chat completion. Model availability, tool support, and output limits depend on the authenticated key and selected model.",
        "tags": [
          "OpenAI compatible"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              },
              "example": {
                "model": "YOUR_AUTHENTICATED_MODEL_ID",
                "messages": [
                  {
                    "role": "user",
                    "content": "Reply with hello."
                  }
                ],
                "max_tokens": 32
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A JSON completion, or server-sent events when stream is true.",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "OpenAI-compatible server-sent event stream ending with [DONE]."
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/OpenAIRequestError"
          },
          "402": {
            "$ref": "#/components/responses/OpenAIQuotaError"
          },
          "401": {
            "$ref": "#/components/responses/OpenAIAuthenticationError"
          },
          "403": {
            "$ref": "#/components/responses/OpenAIPermissionError"
          },
          "404": {
            "$ref": "#/components/responses/OpenAINotFoundError"
          },
          "409": {
            "$ref": "#/components/responses/OpenAIConflictError"
          },
          "429": {
            "$ref": "#/components/responses/OpenAIRateLimitError"
          },
          "502": {
            "$ref": "#/components/responses/OpenAIUpstreamError"
          },
          "503": {
            "$ref": "#/components/responses/OpenAIServiceUnavailable"
          }
        }
      }
    },
    "/v1/responses": {
      "post": {
        "operationId": "createResponse",
        "summary": "Create a Responses API result",
        "description": "Creates an OpenAI-compatible Responses API result. Use input for the request content and max_output_tokens to cap output.",
        "tags": [
          "OpenAI compatible"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResponsesRequest"
              },
              "example": {
                "model": "YOUR_AUTHENTICATED_MODEL_ID",
                "input": "Reply with hello.",
                "max_output_tokens": 32
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A JSON response object, or server-sent events when stream is true.",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResponsesResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "OpenAI-compatible Responses API server-sent event stream."
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/OpenAIRequestError"
          },
          "402": {
            "$ref": "#/components/responses/OpenAIQuotaError"
          },
          "401": {
            "$ref": "#/components/responses/OpenAIAuthenticationError"
          },
          "403": {
            "$ref": "#/components/responses/OpenAIPermissionError"
          },
          "404": {
            "$ref": "#/components/responses/OpenAINotFoundError"
          },
          "409": {
            "$ref": "#/components/responses/OpenAIConflictError"
          },
          "429": {
            "$ref": "#/components/responses/OpenAIRateLimitError"
          },
          "502": {
            "$ref": "#/components/responses/OpenAIUpstreamError"
          },
          "503": {
            "$ref": "#/components/responses/OpenAIServiceUnavailable"
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "operationId": "createMessage",
        "summary": "Create an Anthropic-compatible message",
        "description": "Creates an Anthropic-compatible message. max_tokens is optional at the CloudService boundary and defaults to 1024 when omitted; the effective value is capped at the selected model's published output limit.",
        "tags": [
          "Anthropic compatible"
        ],
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/AnthropicVersion"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnthropicMessageRequest"
              },
              "example": {
                "model": "YOUR_AUTHENTICATED_MODEL_ID",
                "messages": [
                  {
                    "role": "user",
                    "content": "Reply with hello."
                  }
                ],
                "max_tokens": 32
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An Anthropic-format message, or Anthropic-format server-sent events when stream is true.",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicMessageResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Anthropic-compatible server-sent event stream."
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/AnthropicRequestError"
          },
          "402": {
            "$ref": "#/components/responses/AnthropicQuotaError"
          },
          "401": {
            "$ref": "#/components/responses/AnthropicAuthenticationError"
          },
          "403": {
            "$ref": "#/components/responses/AnthropicPermissionError"
          },
          "404": {
            "$ref": "#/components/responses/AnthropicNotFoundError"
          },
          "409": {
            "$ref": "#/components/responses/AnthropicConflictError"
          },
          "429": {
            "$ref": "#/components/responses/AnthropicRateLimitError"
          },
          "502": {
            "$ref": "#/components/responses/AnthropicUpstreamError"
          },
          "503": {
            "$ref": "#/components/responses/AnthropicServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/AnthropicGatewayTimeout"
          }
        }
      }
    },
    "/v1/messages/count_tokens": {
      "post": {
        "operationId": "countMessageTokens",
        "summary": "Count Anthropic request tokens",
        "description": "Returns an input token estimate for a valid Anthropic-format request without creating a model response or deducting model-generation usage.",
        "tags": [
          "Anthropic compatible"
        ],
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/AnthropicVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnthropicTokenCountRequest"
              },
              "example": {
                "model": "YOUR_AUTHENTICATED_MODEL_ID",
                "messages": [
                  {
                    "role": "user",
                    "content": "Reply with hello."
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Estimated input token count.",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenCountResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/AnthropicRequestError"
          },
          "401": {
            "$ref": "#/components/responses/AnthropicAuthenticationError"
          },
          "403": {
            "$ref": "#/components/responses/AnthropicPermissionError"
          },
          "404": {
            "$ref": "#/components/responses/AnthropicNotFoundError"
          },
          "429": {
            "$ref": "#/components/responses/AnthropicRateLimitError"
          },
          "503": {
            "$ref": "#/components/responses/AnthropicServiceUnavailable"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Get authenticated key usage",
        "description": "Returns the key's status, billing mode, scope, request totals, token totals, and available credit or token balance.",
        "tags": [
          "Usage"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Usage summary for the authenticated key.",
            "headers": {
              "x-request-id": {
                "$ref": "#/components/headers/RequestId"
              },
              "x-cloudservice-credit-remaining": {
                "description": "Remaining API credit. Returned for credit-mode keys.",
                "schema": {
                  "type": "number"
                }
              },
              "x-ratelimit-remaining-tokens": {
                "description": "Remaining token budget. Returned for token-mode keys.",
                "schema": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageSummary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/OpenAIAuthenticationError"
          },
          "429": {
            "$ref": "#/components/responses/OpenAIRateLimitError"
          },
          "503": {
            "$ref": "#/components/responses/OpenAIServiceUnavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "CloudService API key",
        "description": "Send the CloudService key as Authorization: Bearer <key>."
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Native Anthropic-compatible alternative to bearer authentication. Send only one authentication method."
      }
    },
    "parameters": {
      "AnthropicVersion": {
        "name": "anthropic-version",
        "in": "header",
        "required": false,
        "description": "Anthropic API compatibility version used by native clients.",
        "schema": {
          "type": "string",
          "example": "2023-06-01"
        }
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Stable identifier for one logical request. Reuse it only when safely retrying that same request.",
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        }
      }
    },
    "headers": {
      "RequestId": {
        "description": "Request identifier to include in a support report.",
        "schema": {
          "type": "string"
        }
      },
      "RetryAfter": {
        "description": "Seconds to wait before a safe retry.",
        "schema": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "responses": {
      "OpenAIRequestError": {
        "description": "Invalid OpenAI-compatible request.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "OpenAIQuotaError": {
        "description": "The API-credit balance or token allocation is too low to start the request.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "OpenAIAuthenticationError": {
        "description": "Missing, invalid, expired, or suspended API key.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "OpenAIPermissionError": {
        "description": "The key is not entitled to the requested provider or model.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "OpenAINotFoundError": {
        "description": "The requested model is not available.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "OpenAIConflictError": {
        "description": "The idempotency key conflicts with another request or duplicates an in-flight request.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "OpenAIRateLimitError": {
        "description": "The key's request rate limit was exceeded.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Retry-After": {
            "$ref": "#/components/headers/RetryAfter"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "OpenAIUpstreamError": {
        "description": "The selected model's upstream provider is unavailable or returned an invalid response.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "OpenAIServiceUnavailable": {
        "description": "A transient gateway, provider, or rate-limiter failure.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Retry-After": {
            "$ref": "#/components/headers/RetryAfter"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OpenAIErrorEnvelope"
            }
          }
        }
      },
      "AnthropicRequestError": {
        "description": "Invalid Anthropic-compatible request.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicQuotaError": {
        "description": "The API-credit balance or token allocation is too low to start the request.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicAuthenticationError": {
        "description": "Missing, invalid, expired, or suspended API key.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicPermissionError": {
        "description": "The key is not entitled to the requested provider or model.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicNotFoundError": {
        "description": "The requested model is not available.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicConflictError": {
        "description": "The idempotency key conflicts with another request or duplicates an in-flight request.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicRateLimitError": {
        "description": "The key's request rate limit was exceeded.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Retry-After": {
            "$ref": "#/components/headers/RetryAfter"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicUpstreamError": {
        "description": "The selected model's upstream provider is unavailable or rejected the request.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicServiceUnavailable": {
        "description": "A transient gateway, provider, or rate-limiter failure.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Retry-After": {
            "$ref": "#/components/headers/RetryAfter"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      },
      "AnthropicGatewayTimeout": {
        "description": "The selected model's upstream provider timed out before completing the request.",
        "headers": {
          "x-request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AnthropicErrorEnvelope"
            }
          }
        }
      }
    },
    "schemas": {
      "FlexibleContent": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          {
            "type": "null"
          }
        ]
      },
      "OpenAIMessage": {
        "type": "object",
        "required": [
          "role"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "developer",
              "system",
              "user",
              "assistant",
              "tool"
            ]
          },
          "content": {
            "$ref": "#/components/schemas/FlexibleContent"
          },
          "name": {
            "type": "string"
          },
          "tool_call_id": {
            "type": "string"
          },
          "tool_calls": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        },
        "additionalProperties": true
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "minLength": 1,
            "description": "Exact ID returned by authenticated GET /v1/models."
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/OpenAIMessage"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "description": "Requested output cap. Must not exceed the selected model's published limit."
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2
          },
          "top_p": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "stop": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "maxItems": 4,
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "additionalProperties": true
              }
            ]
          },
          "user": {
            "type": "string"
          }
        },
        "additionalProperties": true
      },
      "OpenAIUsage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {
            "type": "integer",
            "minimum": 0
          },
          "completion_tokens": {
            "type": "integer",
            "minimum": 0
          },
          "total_tokens": {
            "type": "integer",
            "minimum": 0
          }
        },
        "additionalProperties": true
      },
      "ChatCompletionResponse": {
        "type": "object",
        "required": [
          "id",
          "object",
          "model",
          "choices"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "usage": {
            "$ref": "#/components/schemas/OpenAIUsage"
          }
        },
        "additionalProperties": true
      },
      "ResponsesRequest": {
        "type": "object",
        "required": [
          "model",
          "input"
        ],
        "properties": {
          "model": {
            "type": "string",
            "minLength": 1,
            "description": "Exact ID returned by authenticated GET /v1/models."
          },
          "input": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            ]
          },
          "instructions": {
            "type": "string"
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "max_output_tokens": {
            "type": "integer",
            "minimum": 1,
            "description": "Requested output cap. Must not exceed the selected model's published limit."
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "additionalProperties": true
              }
            ]
          }
        },
        "additionalProperties": true
      },
      "ResponsesResponse": {
        "type": "object",
        "required": [
          "id",
          "object"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "output": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "usage": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "AnthropicContent": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        ]
      },
      "AnthropicInputMessage": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "user",
              "assistant"
            ]
          },
          "content": {
            "$ref": "#/components/schemas/AnthropicContent"
          }
        },
        "additionalProperties": true
      },
      "AnthropicMessageRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "minLength": 1,
            "description": "Exact ID returned by authenticated GET /v1/models."
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/AnthropicInputMessage"
            }
          },
          "system": {
            "$ref": "#/components/schemas/AnthropicContent"
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "default": 1024,
            "description": "Requested output cap; CloudService caps it at the model's published limit."
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number"
          },
          "top_p": {
            "type": "number"
          },
          "top_k": {
            "type": "integer"
          },
          "stop_sequences": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "tool_choice": {
            "type": "object",
            "additionalProperties": true
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "AnthropicTokenCountRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "minLength": 1,
            "description": "Exact ID returned by authenticated GET /v1/models."
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/AnthropicInputMessage"
            }
          },
          "system": {
            "$ref": "#/components/schemas/AnthropicContent"
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "tool_choice": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "TokenCountResponse": {
        "type": "object",
        "required": [
          "input_tokens"
        ],
        "properties": {
          "input_tokens": {
            "type": "integer",
            "minimum": 0
          }
        },
        "additionalProperties": false
      },
      "AnthropicMessageResponse": {
        "type": "object",
        "required": [
          "id",
          "type",
          "role",
          "model",
          "content"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "const": "message"
          },
          "role": {
            "type": "string",
            "const": "assistant"
          },
          "model": {
            "type": "string"
          },
          "content": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "stop_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "stop_sequence": {
            "type": [
              "string",
              "null"
            ]
          },
          "usage": {
            "type": "object",
            "properties": {
              "input_tokens": {
                "type": "integer",
                "minimum": 0
              },
              "output_tokens": {
                "type": "integer",
                "minimum": 0
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "ModelList": {
        "type": "object",
        "required": [
          "object",
          "data"
        ],
        "properties": {
          "object": {
            "type": "string",
            "const": "list"
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Model"
            }
          }
        },
        "additionalProperties": false
      },
      "Model": {
        "type": "object",
        "required": [
          "id",
          "object",
          "created",
          "owned_by"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Exact model identifier to use in API requests."
          },
          "object": {
            "type": "string",
            "const": "model"
          },
          "created": {
            "type": "integer"
          },
          "owned_by": {
            "type": "string"
          },
          "display_name": {
            "type": "string"
          },
          "tagline": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "context_window": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "max_output_tokens": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "capabilities": {
            "type": "object",
            "additionalProperties": true
          },
          "pricing": {
            "type": "object",
            "description": "Published customer-facing pricing metadata when available.",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "UsageSummary": {
        "type": "object",
        "required": [
          "object",
          "key",
          "credits",
          "tokens",
          "requests",
          "explanation"
        ],
        "properties": {
          "object": {
            "type": "string",
            "const": "usage.summary"
          },
          "key": {
            "$ref": "#/components/schemas/UsageKey"
          },
          "credits": {
            "$ref": "#/components/schemas/CreditUsage"
          },
          "tokens": {
            "$ref": "#/components/schemas/TokenUsage"
          },
          "requests": {
            "type": "object",
            "required": [
              "total"
            ],
            "properties": {
              "total": {
                "type": "integer",
                "minimum": 0
              }
            },
            "additionalProperties": false
          },
          "explanation": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "UsageKey": {
        "type": "object",
        "required": [
          "prefix",
          "label",
          "status",
          "mode",
          "provider_scope"
        ],
        "properties": {
          "prefix": {
            "type": "string",
            "description": "Non-secret key prefix."
          },
          "label": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "credit",
              "token_budget"
            ]
          },
          "provider_scope": {
            "type": "string"
          },
          "rpm_limit": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          }
        },
        "additionalProperties": false
      },
      "CreditUsage": {
        "type": "object",
        "required": [
          "total_purchased",
          "balance",
          "reserved",
          "used",
          "remaining",
          "remaining_usd",
          "last_request_cost",
          "today_spend",
          "lifetime_spend"
        ],
        "properties": {
          "total_purchased": {
            "type": "number"
          },
          "balance": {
            "type": "number"
          },
          "reserved": {
            "type": "number"
          },
          "used": {
            "type": "number"
          },
          "remaining": {
            "type": "number"
          },
          "remaining_usd": {
            "type": "number"
          },
          "last_request_cost": {
            "type": "number"
          },
          "today_spend": {
            "type": "number"
          },
          "lifetime_spend": {
            "type": "number"
          }
        },
        "additionalProperties": false
      },
      "TokenUsage": {
        "type": "object",
        "required": [
          "budget",
          "used",
          "reserved",
          "remaining",
          "input",
          "output",
          "total"
        ],
        "properties": {
          "budget": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "used": {
            "type": "integer",
            "minimum": 0
          },
          "reserved": {
            "type": "integer",
            "minimum": 0
          },
          "remaining": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "input": {
            "type": "integer",
            "minimum": 0
          },
          "output": {
            "type": "integer",
            "minimum": 0
          },
          "total": {
            "type": "integer",
            "minimum": 0
          }
        },
        "additionalProperties": false
      },
      "OpenAIErrorEnvelope": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "message",
              "type",
              "code"
            ],
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "param": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "request_id": {
                "type": "string"
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "AnthropicErrorEnvelope": {
        "type": "object",
        "required": [
          "type",
          "error"
        ],
        "properties": {
          "type": {
            "type": "string",
            "const": "error"
          },
          "error": {
            "type": "object",
            "required": [
              "type",
              "message"
            ],
            "properties": {
              "type": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            },
            "additionalProperties": true
          },
          "request_id": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    }
  }
}
