Messages
POST /v1/messages: a text request in the Anthropic Messages format.
/v1/messagesSends a conversation to a text model in the Anthropic Messages format. client.messages.create(...) from the Anthropic SDK and Claude Code works. Any text model in the catalog accepts this format, not only Anthropic models.
Headers
| Header | Value |
|---|---|
x-api-key | The Morphogen key. Required. Authorization: Bearer <key> is accepted instead |
anthropic-version | 2023-06-01. The Anthropic SDK adds it itself |
Content-Type | application/json |
X-PII-Masking | on or off. PII masking |
X-Morphogen-Space | spc_…: the spending space. Optional |
Request body
modelstringrequiredA model name from GET /v1/models.
max_tokensintegerrequiredThe maximum response length. In this format the field is required.
messagesarrayrequiredConversation messages: objects with role (user or assistant) and content as a string or blocks (text, image, tool_use, tool_result).
systemstring | arrayThe system instruction.
streambooleantrue turns on a streaming response in the Anthropic event format.
toolsarrayTool descriptions. Works on models that support tool use.
The cache_control block passes through as is: on Claude it turns on the explicit prompt cache. The other fields of the format go to the model unchanged.
Request example
curl https://api.morphogen.ru/v1/messages \
-H "x-api-key: $MORPHOGEN_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 200,
"messages": [{"role": "user", "content": "Назови столицу Франции одним словом"}]
}'Give the base_url URL without /v1: the SDK adds the path itself.
Response example
{
"id": "msg_01Qx7LrT",
"type": "message",
"role": "assistant",
"model": "anthropic/claude-sonnet-5",
"content": [{ "type": "text", "text": "Париж" }],
"stop_reason": "end_turn",
"usage": { "input_tokens": 18, "output_tokens": 3 }
}input_tokens includes the whole input, cache tokens too. If the model spent the whole max_tokens on reasoning, the response comes without text, with stop_reason: "max_tokens".
Errors
Errors come in the Anthropic format: {"type": "error", "error": {"type": "...", "message": "..."}}. There is no error.code field, except for key_revoked: tell errors apart by the HTTP status, error.type and the error.message text. The codes in the table below are named as on the errors page.
invalid_jsonThe request body could not be parsed.model_category_mismatchThe model is not a text model.invalid_api_keyThe key is missing, invalid, revoked or expired.insufficient_fundsThe balance does not cover the request reserve.key_limit_exceededThe daily or monthly key limit is used up.model_not_allowedThe model is not in the key's list.model_not_foundThere is no such model in the catalog.request_too_largeThe request body is larger than 32 MiB.rate_limit_exceededThe request or token limit per minute is exceeded. Retry after the time in Retry-After.Other codes: Errors.