POST /v1/messaggi
API Anthropic Messages per chat, streaming, visione, strumenti, memorizzazione nella cache e pensiero.
POST /v1/messaggi
Il principale endpoint antropico-compatibile. Supporta lo streaming, la memorizzazione nella cache immediata, la visione, l'uso degli strumenti e il pensiero esteso quando supportato dal modello selezionato.
Autenticazione
x-api-key: mg_live_...\nanthropic-version: 2023-06-01\ncontent-type: application/json
Richiesta minima
curl https://api.model-gate.com/v1/messages \
-H "x-api-key: mg_live_..." \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4.8",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'
Richiesta avanzata
{
"model": "claude-opus-4.8",
"max_tokens": 4096,
"system": "You are a coding assistant.",
"thinking": {"type": "enabled", "budget_tokens": 8000},
"messages": [{"role": "user", "content": "Find the bug in this code."}],
"tools": [{
"name": "search_files",
"description": "Search project files",
"input_schema": {"type": "object", "properties": {"q": {"type": "string"}}}
}]
}
Visione
{
"model": "claude-opus-4.8",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is shown in this image?"},
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "..."}}
]
}]
}
Memorizzazione nella cache immediata
{
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Large reusable context...", "cache_control": {"type": "ephemeral"}},
{"type": "text", "text": "New question"}
]
}]
}
Streaming
Impostato "stream": true. La risposta viene restituita come eventi inviati dal server.
Risposta
{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "claude-opus-4.8",
"content": [{"type": "text", "text": "Hello!"}],
"stop_reason": "end_turn",
"usage": {"input_tokens": 12, "output_tokens": 8}
}
La struttura di richiesta e risposta segue l'API Anthropic Messages. Gli SDK antropici esistenti normalmente richiedono solo il file base_url modifica.