{ "openapi": "3.0.0", "info": { "title": "Anthropic Messages API", "version": "1.0.0", "description": "API for interacting with Anthropic's language models and counting tokens" }, "servers": [ { "url": "https://api.anthropic.com/v1" } ], "paths": { "/messages": { "post": { "summary": "Create a new message", "operationId": "createMessage", "tags": [ "Messages" ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MessageRequest" } } } }, "responses": { "200": { "description": "Successful response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MessageResponse" } } } } } } }, "/messages/count_tokens": { "post": { "summary": "Count tokens in messages", "operationId": "countTokens", "tags": [ "Messages" ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CountTokensRequest" } } } }, "responses": { "200": { "description": "Successful response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CountTokensResponse" } } } } } } } }, "components": { "securitySchemes": { "ApiKeyAuth": { "type": "apiKey", "in": "header", "name": "X-API-Key" }, "AnthropicVersionHeader": { "type": "apiKey", "in": "header", "name": "anthropic-version" }, "AnthropicBetaHeader": { "type": "apiKey", "in": "header", "name": "anthropic-beta" } }, "schemas": { "MessageRequest": { "type": "object", "required": [ "model", "messages" ], "properties": { "model": { "type": "string", "description": "The model that will complete your prompt" }, "messages": { "type": "array", "items": { "$ref": "#/components/schemas/Message" } }, "max_tokens": { "type": "integer", "description": "The maximum number of tokens to generate before stopping" }, "metadata": { "type": "object", "description": "An object describing metadata about the request" }, "stop_sequences": { "type": "array", "items": { "type": "string" }, "description": "Custom text sequences that will cause the model to stop generating" }, "stream": { "type": "boolean", "description": "Whether to incrementally stream the response using server-sent events" }, "system": { "type": "string", "description": "System prompt" }, "temperature": { "type": "number", "description": "Amount of randomness injected into the response", "default": 1, "minimum": 0, "maximum": 1 }, "tools": { "type": "array", "items": { "$ref": "#/components/schemas/Tool" } }, "tool_choice": { "type": "string", "enum": [ "none", "auto", "any" ], "description": "How the model should use the provided tools" }, "top_p": { "type": "number", "description": "Use nucleus sampling" }, "top_k": { "type": "integer", "description": "Only sample from the top K options for each subsequent token" } } }, "CountTokensRequest": { "type": "object", "required": [ "model", "messages" ], "properties": { "model": { "type": "string", "description": "The model that will be used to count tokens" }, "messages": { "type": "array", "items": { "$ref": "#/components/schemas/Message" } }, "system": { "type": "string", "description": "System prompt" }, "tools": { "type": "array", "items": { "$ref": "#/components/schemas/Tool" } } } }, "Message": { "type": "object", "required": [ "role", "content" ], "properties": { "role": { "type": "string", "enum": [ "user", "assistant" ] }, "content": { "oneOf": [ { "type": "string" }, { "type": "array", "items": { "$ref": "#/components/schemas/ContentBlock" } } ] } } }, "ContentBlock": { "oneOf": [ { "$ref": "#/components/schemas/TextBlock" }, { "$ref": "#/components/schemas/ImageBlock" } ] }, "TextBlock": { "type": "object", "required": [ "type", "text" ], "properties": { "type": { "type": "string", "enum": [ "text" ] }, "text": { "type": "string" } } }, "ImageBlock": { "type": "object", "required": [ "type", "source" ], "properties": { "type": { "type": "string", "enum": [ "image" ] }, "source": { "$ref": "#/components/schemas/ImageSource" } } }, "ImageSource": { "type": "object", "required": [ "type", "media_type", "data" ], "properties": { "type": { "type": "string", "enum": [ "base64" ] }, "media_type": { "type": "string", "enum": [ "image/jpeg", "image/png", "image/gif", "image/webp" ] }, "data": { "type": "string" } } }, "Tool": { "type": "object", "required": [ "name", "input_schema" ], "properties": { "name": { "type": "string" }, "description": { "type": "string" }, "input_schema": { "type": "object" } } }, "MessageResponse": { "type": "object", "required": [ "id", "type", "role", "content", "model", "stop_reason", "usage" ], "properties": { "id": { "type": "string" }, "type": { "type": "string", "enum": [ "message" ] }, "role": { "type": "string", "enum": [ "assistant" ] }, "content": { "type": "array", "items": { "$ref": "#/components/schemas/ContentBlock" } }, "model": { "type": "string" }, "stop_reason": { "type": "string", "enum": [ "end_turn", "max_tokens", "stop_sequence", "tool_use" ] }, "stop_sequence": { "type": "string" }, "usage": { "$ref": "#/components/schemas/Usage" } } }, "CountTokensResponse": { "type": "object", "required": [ "token_count" ], "properties": { "token_count": { "type": "integer", "description": "The total number of tokens across the provided list of messages," } } } } } }