chat

Create a message

Mirrors Anthropic's Messages API so Anthropic SDKs and agents run against Morph models by changing the base URL and API key only — request and response shapes are unchanged. Set stream: true to receive the message as a text/event-stream of Anthropic-style events; the 200 response below documents the non-streaming shape.

post/v1/messages

Request body

modelstring required

ID of the Morph model to use

max_tokensinteger required

Maximum number of tokens to generate before stopping

systemstring

System prompt applied ahead of the conversation

streamboolean

Enable streaming response. When true the response is a text/event-stream of Anthropic-style message_start, content_block_delta, and message_stop events.

temperaturenumber

Sampling temperature for the Messages request (0.0 for deterministic output)

Example request

{
  "model": "morph-glm52-744b",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "Refactor this Express route to use async/await."
    }
  ],
  "system": "You are a senior TypeScript engineer. Reply with code only.",
  "stream": false,
  "temperature": 0
}

Response

Message response

idstring required

Unique identifier for the message

type'message' required

Object type, always message

role'assistant' required

The role of the message author, always assistant on a response

modelstring required

ID of the model that produced the message

stop_reason'end_turn' | 'max_tokens' | 'stop_sequence' required

Why the model stopped generating tokens

Example response

{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "router.get(\"/users\", async (req, res) => {\n  const users = await db.users.findMany();\n  res.json(users);\n});"
    }
  ],
  "model": "morph-glm52-744b",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 42,
    "output_tokens": 37
  }
}

Changes