> For the complete documentation index, see [llms.txt](https://docs.cortecs.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cortecs.ai/api-overview/anthropic-messages-beta.md).

# Anthropic Messages \[BETA]

{% hint style="warning" %}
This endpoint is currently in beta. For any issues or feedback, please contact us via [Discord](https://discord.com/invite/bPFEFcWBhp) or <support@cortecs.ai>.
{% endhint %}

## POST /messages

> Create a messages response. This endpoint is compatible with the Anthropic API.

```json
{"openapi":"3.1.0","info":{"title":"Cortecs Anthropic Messages API","version":"1.0.0"},"servers":[{"url":"https://api.cortecs.ai/v1"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"MessageRequest":{"type":"object","description":"Request message for /v1/messages","properties":{"preference":{"type":"string","description":"The provider preference for handling the request.","enum":["speed","cost","balanced"]},"allowed_providers":{"type":"array","items":{"type":"string"},"description":"The providers that are allowed to be used for the completion.","nullable":true},"eu_native":{"type":"boolean","description":"Whether to consider only providers based and regulated withing the EU. Even when false, all our endpoints are GDPR compliant.","nullable":true},"allow_quantization":{"type":"boolean","description":"Whether to allow quantized endpoints.","nullable":true},"allow_zero_data_retention":{"type":"boolean","description":"Whether to use only ZDR providers.","nullable":true},"enable_model_fallback":{"type":"boolean","description":"Whether to allow model fallback when a model is currently unavailable.","nullable":true},"fallbacks":{"type":"array","items":{"type":"string"},"description":"The providers that are allowed to be used for the completion.","nullable":true},"max_tokens":{"type":"integer","format":"int32","description":"The maximum number of tokens to generate before stopping. The model may stop before the max_tokens when it reaches the stop sequence."},"messages":{"type":"array","items":{"$ref":"#/components/schemas/MessageBody"},"description":"Input messages."},"metadata":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/MessageMetadata","description":"An object describing metadata about the request."}]},"model":{"type":"string","description":"Model name for the model to use."},"stop_sequences":{"type":["array","null"],"items":{"type":"string"},"description":"(Not supported by reasoning models) Up to 4 sequences where the API will stop generating further tokens."},"stream":{"type":["boolean","null"],"description":"If set, partial message deltas will be sent. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message."},"system":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/SystemMessageContent","description":"System prompt message for the model, defining how the model should behave to user messages."}]},"temperature":{"type":["number","null"],"format":"float","description":"What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. It may not work well with reasoning models.","default":1,"maximum":2,"minimum":0},"tool_choice":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/MessageToolChoice","description":"Controls which (if any) tool is called by the model. \"none\" means the model will not call any tool and instead generates a message. \"auto\" means the model can pick between generating a message or calling one or more tools. \"any\" means the model must call one or more tools. Specifying a particular tool via {\"type\": \"tool\", \"function\": {\"name\": \"get_weather\"}} forces the model to call that tool. \"none\" is the default when no tools are provided. \"auto\" is the default if tools are provided."}]},"tools":{"type":["array","null"],"items":{"$ref":"#/components/schemas/MessageTools"},"description":"A list of tools the model may call in JSON-schema. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported."},"top_k":{"type":["integer","null"],"format":"int32","description":"(Unsupported) When generating next tokens, randomly selecting the next token from the k most likely options."},"top_p":{"type":["number","null"],"format":"float","description":"An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. It is generally recommended to alter this or temperature but not both.","default":1,"maximum":1,"exclusiveMinimum":0}}},"MessageBody":{"type":"object","description":"Anthropic compatible message body","required":["role","content"],"properties":{"content":{"$ref":"#/components/schemas/MessageContent","description":"The content message."},"role":{"type":"string","description":"The role that the message belongs to, \"system\" for system prompt, \"user\" for user prompt, and \"assistant\" for response from the model."}}},"MessageContent":{"oneOf":[{"type":"string","description":"Text prompt."},{"type":"array","items":{"$ref":"#/components/schemas/MessageContentPart"},"description":"An array of message content parts."}]},"MessageContentPart":{"oneOf":[{"type":"object","description":"Text prompt message content part.","required":["text","type"],"properties":{"cache_control":{"description":"(Unsupported) Cache control."},"text":{"type":"string","description":"Text prompt."},"type":{"type":"string","enum":["text"]}}},{"type":"object","description":"Image prompt message content part.","required":["source","type"],"properties":{"cache_control":{"description":"(Unsupported) Cache control."},"source":{"$ref":"#/components/schemas/MessageImageContent","description":"Image source."},"type":{"type":"string","enum":["image"]}}},{"type":"object","description":"Tool call message content part. Received from model.","required":["id","name","input","type"],"properties":{"cache_control":{"description":"(Unsupported) Cache control."},"id":{"type":"string","description":"ID of the tool call."},"input":{"description":"Input for tool call."},"name":{"type":"string","description":"Name of the tool call."},"type":{"type":"string","enum":["tool_use"]}}},{"type":"object","description":"Tool call result.","required":["tool_use_id","content","type"],"properties":{"cache_control":{"description":"(Unsupported) Cache control."},"content":{"$ref":"#/components/schemas/ToolResultContent","description":"Result content of the tool call. Can be a string or an array of content blocks."},"is_error":{"type":["boolean","null"],"description":"Whether the tool call returns an error."},"tool_use_id":{"type":"string","description":"ID of the tool call given by the model."},"type":{"type":"string","enum":["tool_result"]}}},{"type":"object","description":"(Redacted) Thinking of the model.","required":["data","type"],"properties":{"data":{"type":"string","description":"Encrypted data of the redacted thinking."},"type":{"type":"string","enum":["redacted_thinking"]}}},{"type":"object","description":"Thinking of the model.","required":["thinking","type"],"properties":{"signature":{"type":["string","null"],"description":"Signature of the thinking block (required by Anthropic SDK for round-tripping)."},"thinking":{"type":"string","description":"Thinking."},"type":{"type":"string","enum":["thinking"]}}}]},"MessageImageContent":{"oneOf":[{"type":"object","required":["media_type","data","type"],"properties":{"data":{"type":"string","description":"Base64 encoded image string."},"media_type":{"type":"string","description":"Media type of the image source. Available options: image/jpeg, image/png, image/webp."},"type":{"type":"string","enum":["base64"]}}},{"type":"object","required":["url","type"],"properties":{"type":{"type":"string","enum":["url"]},"url":{"type":"string","description":"URL of the image."}}}]},"ToolResultContent":{"oneOf":[{"type":"string","description":"Plain text content."},{"type":"array","items":{"$ref":"#/components/schemas/ToolResultContentBlock"},"description":"An array of tool result content blocks."}]},"ToolResultContentBlock":{"type":"object","description":"A content block within a tool result.","properties":{"type":{"type":"string","description":"The type of content block."},"text":{"type":"string","description":"Text content of the block."}}},"MessageMetadata":{"type":"object","properties":{"user_id":{"type":["string","null"],"description":"A unique identifier representing your end-user, which can help to monitor and detect abuse."}}},"SystemMessageContent":{"oneOf":[{"type":"string","description":"Text content of system prompt."},{"type":"array","items":{"$ref":"#/components/schemas/SystemMessagePart"},"description":"An array of system prompt parts."}]},"SystemMessagePart":{"type":"object","required":["type","text"],"properties":{"cache_control":{"description":"(Unsupported) Cache control."},"text":{"type":"string","description":"System prompt text."},"type":{"type":"string","description":"Type of the object. This is always \"text\"."}}},"MessageToolChoice":{"oneOf":[{"type":"object","description":"Allows the model to automatically decide whether to call the tool.","required":["type"],"properties":{"type":{"type":"string","enum":["auto"]}}},{"type":"object","description":"Forces the model to use at least one tool, without specifying the tool.","required":["type"],"properties":{"type":{"type":"string","enum":["any"]}}},{"type":"object","description":"Forces the model to use the named tool.","required":["name","type"],"properties":{"name":{"type":"string","description":"Name of the tool to use."},"type":{"type":"string","enum":["tool"]}}}],"description":"Tool choice option."},"MessageTools":{"type":"object","required":["name","description","input_schema"],"properties":{"cache_control":{"description":"(Unsupported) Cache control."},"description":{"type":"string","description":"Description of the tool."},"input_schema":{"$ref":"#/components/schemas/MessageToolInputSchema","description":"Input schema allowed by the tool."},"name":{"type":"string","description":"Name of the tool."}}},"MessageToolInputSchema":{"type":"object","required":["type","properties"],"properties":{"properties":{"description":"JSON-object of the tool input schema."},"required":{"type":["array","null"],"items":{"type":"string"},"description":"Required properties of the tool input schema, if any."},"type":{"type":"string","description":"Type of the schema. This is always \"object\"."}}},"MessageResponse":{"type":"object","description":"Response message for /v1/messages","required":["id","type","role","content","model","usage"],"properties":{"content":{"type":"array","items":{"$ref":"#/components/schemas/MessageResponseContent"},"description":"Response message content."},"id":{"type":"string","description":"Unique object identifier."},"model":{"type":"string","description":"Model name that handled the request."},"role":{"type":"string","description":"Role of the generated message. Always \"assistant\"."},"stop_reason":{"type":["string","null"],"description":"Reason to stop. \"stop_sequence\" means the inference has reached a model-defined or user-supplied stop sequence in stop. \"max_tokens\" means the inference result has reached models' maximum allowed token length or user defined value in max_tokens. \"end_turn\" or null in streaming mode when the chunk is not the last. \"tool_use\" means the model has called a tool and is waiting for the tool response."},"stop_sequence":{"type":["string","null"],"description":"Custom stop sequence used to stop the generation."},"type":{"type":"string","description":"Object type. This is always \"message\" for message types."},"usage":{"$ref":"#/components/schemas/MessageUsage","description":"Token usage information."}}},"MessageResponseContent":{"oneOf":[{"type":"object","description":"Text response from the model.","required":["text","type"],"properties":{"text":{"type":"string"},"type":{"type":"string","enum":["text"]}}},{"type":"object","description":"Thinking response for the model.","required":["signature","thinking","type"],"properties":{"signature":{"type":"string","description":"Signature of the content."},"thinking":{"type":"string","description":"Thinking content."},"type":{"type":"string","enum":["thinking"]}}},{"type":"object","description":"Redacted thinking response for the model.","required":["data","type"],"properties":{"data":{"type":"string","description":"Signature of the content."},"type":{"type":"string","enum":["redacted_thinking"]}}},{"type":"object","description":"Request by the model to invoke a tool call.","required":["id","name","input","type"],"properties":{"id":{"type":"string","description":"Tool call ID."},"input":{"description":"Input to the tool call following the input_schema."},"name":{"type":"string","description":"Name of the tool call to be used."},"type":{"type":"string","enum":["tool_use"]}}}]},"MessageUsage":{"type":"object","required":["input_tokens","cache_creation_input_tokens","cache_read_input_tokens","output_tokens"],"properties":{"cache_creation_input_tokens":{"type":"integer","format":"int32","description":"(Unsupported) Number of tokens written to the cache when creating a new entry."},"cache_read_input_tokens":{"type":"integer","format":"int32","description":"Number of tokens retrieved from the cache for this request."},"input_tokens":{"type":"integer","format":"int32","description":"Number of input tokens used."},"output_tokens":{"type":"integer","format":"int32","description":"Number of output tokens used."}}}}},"paths":{"/messages":{"post":{"tags":["v1"],"summary":"Create a messages response. This endpoint is compatible with the Anthropic API.","operationId":"handle_generic_messages_request","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"description":"Bad request. The request is invalid or an invalid API key is provided."},"422":{"description":"Unprocessable Entity. There are missing fields in the request body."}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cortecs.ai/api-overview/anthropic-messages-beta.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
