{
  "openapi": "3.1.0",
  "info": {
    "title": "Claudes Gateway – Proposed Contract",
    "version": "0.1.0",
    "description": "Proposed first release. No live Claudes API is available in the website preview. Replace the reserved example host with an authorized development deployment."
  },
  "servers": [
    {
      "url": "https://api.claudes.example",
      "description": "Reserved example domain"
    }
  ],
  "security": [
    {
      "gatewayBearer": []
    }
  ],
  "paths": {
    "/v1/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List models permitted for the supplied gateway credential",
        "responses": {
          "200": {
            "description": "Permitted models",
            "headers": {
              "request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Model"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/RateLimit"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "operationId": "createMessage",
        "summary": "Create a message or stream it as SSE",
        "parameters": [
          {
            "$ref": "#/components/parameters/AnthropicVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMessage"
              },
              "example": {
                "model": "claude-demo",
                "max_tokens": 128,
                "messages": [
                  {
                    "role": "user",
                    "content": "Suggest a name for a notes app."
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Message or event stream according to the stream field",
            "headers": {
              "request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AssistantMessage"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Anthropic Messages SSE. A stream is complete only after message_stop. An error event can arrive after HTTP 200."
                },
                "example": "event: message_stop\ndata: {\"type\":\"message_stop\"}\n\n"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/RateLimit"
          },
          "502": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "504": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/messages/count_tokens": {
      "post": {
        "operationId": "countInputTokens",
        "summary": "Count input tokens without generating a message",
        "parameters": [
          {
            "$ref": "#/components/parameters/AnthropicVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CountTokens"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Input token estimate",
            "headers": {
              "request-id": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "input_tokens"
                  ],
                  "properties": {
                    "input_tokens": {
                      "type": "integer",
                      "minimum": 0
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/RateLimit"
          },
          "502": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "504": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "gatewayBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "A gateway-issued credential for the selected environment."
      }
    },
    "parameters": {
      "AnthropicVersion": {
        "name": "anthropic-version",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "const": "2023-06-01"
        },
        "description": "Version targeted by this draft."
      }
    },
    "headers": {
      "RequestId": {
        "description": "Gateway request identifier.",
        "schema": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "responses": {
      "Error": {
        "description": "HTTP error before streaming",
        "headers": {
          "request-id": {
            "$ref": "#/components/headers/RequestId"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimit": {
        "description": "Rate limit or exhausted quota",
        "headers": {
          "request-id": {
            "$ref": "#/components/headers/RequestId"
          },
          "Retry-After": {
            "description": "Delay in seconds when a temporary retry window is known.",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Model": {
        "type": "object",
        "required": [
          "id",
          "display_name"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "display_name": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "ContentBlock": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string"
          }
        },
        "description": "Additional fields depend on the block type and model, for example input and id on tool_use."
      },
      "InputMessage": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "user",
              "assistant"
            ]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ContentBlock"
                }
              }
            ]
          }
        }
      },
      "CreateMessage": {
        "type": "object",
        "required": [
          "model",
          "messages",
          "max_tokens"
        ],
        "properties": {
          "model": {
            "type": "string",
            "minLength": 1
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InputMessage"
            },
            "minItems": 1
          },
          "system": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ContentBlock"
                }
              }
            ]
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "stream": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "CountTokens": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "minLength": 1
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InputMessage"
            },
            "minItems": 1
          },
          "system": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ContentBlock"
                }
              }
            ]
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "description": "Uses the same input context as Messages. max_tokens and stream are not part of this operation."
      },
      "AssistantMessage": {
        "type": "object",
        "required": [
          "id",
          "type",
          "role",
          "model",
          "content",
          "stop_reason",
          "usage"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "type": {
            "const": "message"
          },
          "role": {
            "const": "assistant"
          },
          "model": {
            "type": "string",
            "minLength": 1
          },
          "content": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContentBlock"
            }
          },
          "stop_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "usage": {
            "type": "object",
            "required": [
              "input_tokens",
              "output_tokens"
            ],
            "properties": {
              "input_tokens": {
                "type": "integer",
                "minimum": 0
              },
              "output_tokens": {
                "type": "integer",
                "minimum": 0
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "type",
          "error",
          "request_id"
        ],
        "properties": {
          "type": {
            "const": "error"
          },
          "error": {
            "type": "object",
            "required": [
              "type",
              "message"
            ],
            "properties": {
              "type": {
                "type": "string",
                "minLength": 1
              },
              "message": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "request_id": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  }
}
