MorphogenDocs
API

Messages

POST /v1/messages: a text request in the Anthropic Messages format.

POST/v1/messages

Sends 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

HeaderValue
x-api-keyThe Morphogen key. Required. Authorization: Bearer <key> is accepted instead
anthropic-version2023-06-01. The Anthropic SDK adds it itself
Content-Typeapplication/json
X-PII-Maskingon or off. PII masking
X-Morphogen-Spacespc_…: the spending space. Optional

Request body

modelstringrequired

A model name from GET /v1/models.

max_tokensintegerrequired

The maximum response length. In this format the field is required.

messagesarrayrequired

Conversation messages: objects with role (user or assistant) and content as a string or blocks (text, image, tool_use, tool_result).

systemstring | array

The system instruction.

streamboolean

true turns on a streaming response in the Anthropic event format.

toolsarray

Tool 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.

400invalid_jsonThe request body could not be parsed.
400model_category_mismatchThe model is not a text model.
401invalid_api_keyThe key is missing, invalid, revoked or expired.
402insufficient_fundsThe balance does not cover the request reserve.
402key_limit_exceededThe daily or monthly key limit is used up.
403model_not_allowedThe model is not in the key's list.
404model_not_foundThere is no such model in the catalog.
413request_too_largeThe request body is larger than 32 MiB.
429rate_limit_exceededThe request or token limit per minute is exceeded. Retry after the time in Retry-After.
503service_unavailableThe service is temporarily unavailable. Retry the request.

Other codes: Errors.

On this page