Anthropic Messages
Usa la API Anthropic Messages a través de CometAPI para acceder a modelos Claude con thinking extendido, almacenamiento en caché de prompts, uso de herramientas, búsqueda/recuperación web, streaming y control de esfuerzo.
CometAPI es compatible de forma nativa con la API Anthropic Messages, lo que te da acceso directo a los modelos Claude con todas las funciones específicas de Anthropic. Usa este endpoint para capacidades exclusivas de Claude, como thinking extendido, almacenamiento en caché de prompts y control de esfuerzo.Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
x-api-key como Authorization: Bearer para la autenticación. Los SDK oficiales de Anthropic usan x-api-key de forma predeterminada.Inicio rápido
Para usar el SDK oficial de Anthropic con CometAPI, configura la URL base:Habilitar thinking extendido
Habilita el razonamiento paso a paso de Claude con el parámetrothinking. La respuesta incluye bloques de contenido thinking que muestran el razonamiento interno de Claude antes de la respuesta final.
Almacenar prompts en caché
Para reducir la latencia y el costo en solicitudes posteriores, almacena en caché prompts de sistema grandes o prefijos de conversación. Agregacache_control a los bloques de contenido que deban almacenarse en caché:
usage de la respuesta:
cache_creation_input_tokens— tokens escritos en la caché (facturados a una tarifa más alta)cache_read_input_tokens— tokens leídos desde la caché (facturados a una tarifa reducida)
Streaming de respuestas
Para transmitir respuestas usando Server-Sent Events (SSE), establecestream: true. Los eventos llegan en este orden:
message_start— contiene los metadatos del mensaje y el uso inicialcontent_block_start— marca el inicio de cada bloque de contenidocontent_block_delta— fragmentos de texto incrementales (text_delta)content_block_stop— marca el final de cada bloque de contenidomessage_delta—stop_reasonfinal yusagecompletomessage_stop— señala el final del stream
Controlar el esfuerzo
Para controlar cuánto esfuerzo pone Claude en generar una respuesta, usaoutput_config.effort:
Usar herramientas del servidor
Claude admite herramientas del lado del servidor que se ejecutan en la infraestructura de Anthropic:- Web Fetch
- Web Search
Ejemplo de respuesta
Una respuesta típica del endpoint Anthropic de CometAPI:Comparar con el endpoint compatible con OpenAI
| Función | Anthropic Messages (/v1/messages) | Compatible con OpenAI (/v1/chat/completions) |
|---|---|---|
| Pensamiento extendido | parámetro thinking con budget_tokens | No disponible |
| Almacenamiento en caché de Prompt | cache_control en bloques de contenido | No disponible |
| Control de esfuerzo | output_config.effort | No disponible |
| Web fetch/search | Herramientas del servidor (web_fetch, web_search) | No disponible |
| Encabezado de autenticación | x-api-key o Bearer | Solo Bearer |
| Formato de respuesta | Formato Anthropic (content blocks) | Formato OpenAI (choices, message) |
| Modelos | Solo Claude | Multi-provider (GPT, Claude, Gemini, etc.) |
Autorizaciones
Your CometAPI key passed via the x-api-key header. Authorization: Bearer <key> is also supported.
Encabezados
The Anthropic API version to use. Defaults to 2023-06-01.
"2023-06-01"
Comma-separated list of beta features to enable. Examples: max-tokens-3-5-sonnet-2024-07-15, pdfs-2024-09-25, output-128k-2025-02-19.
Cuerpo
The Claude model to use. See the Models page for current Claude model IDs.
"claude-sonnet-4-6"
The conversation messages. Must alternate between user and assistant roles. Each message's content can be a string or an array of content blocks (text, image, document, tool_use, tool_result). There is a limit of 100,000 messages per request.
The maximum number of tokens to generate. The model may stop before reaching this limit. When using thinking, the thinking tokens count towards this limit.
x >= 11024
System prompt providing context and instructions to Claude. Can be a plain string or an array of content blocks (useful for prompt caching).
Controls randomness in the response. Range: 0.0–1.0. Use lower values for analytical tasks and higher values for creative tasks. Defaults to 1.0.
0 <= x <= 1Nucleus sampling threshold. Only tokens with cumulative probability up to this value are considered. Range: 0.0–1.0. Use either temperature or top_p, not both.
0 <= x <= 1Only sample from the top K most probable tokens. Recommended for advanced use cases only.
x >= 0If true, stream the response incrementally using Server-Sent Events (SSE). Events include message_start, content_block_start, content_block_delta, content_block_stop, message_delta, and message_stop.
Custom strings that cause the model to stop generating when encountered. The stop sequence is not included in the response.
Enable extended thinking — Claude's step-by-step reasoning process. When enabled, the response includes thinking content blocks before the answer. Requires a minimum budget_tokens of 1,024.
Tools the model may use. Supports client-defined functions, web search (web_search_20250305), web fetch (web_fetch_20250910), code execution (code_execution_20250522), and more.
Controls how the model uses tools.
Request metadata for tracking and analytics.
Configuration for output behavior.
The service tier to use. auto tries priority capacity first, standard_only uses only standard capacity.
auto, standard_only Respuesta
Successful response. When stream is true, the response is a stream of SSE events.
Unique identifier for this message (e.g., msg_01XFDUDYJgAACzvnptvVoYEL).
Always message.
message Always assistant.
assistant The response content blocks. May include text, thinking, tool_use, and other block types.
The specific model version that generated this response (e.g., claude-sonnet-4-6).
Why the model stopped generating.
end_turn, max_tokens, stop_sequence, tool_use, pause_turn The stop sequence that caused the model to stop, if applicable.
Token usage statistics.