chat

Create a chat completion

Apply changes from big models into your files. Find your API key. The endpoint is OpenAI-compatible and serves two request shapes, selected by model: Morph Apply (morph-v3-fast, morph-v3-large, auto) merges an edit snippet into an original file, and Warp Grep (morph-warp-grep-v1) runs an agentic repository search. Set stream: true to receive the completion as a text/event-stream of chat.completion.chunk deltas; the 200 response below documents the non-streaming shape.

post/v1/chat/completions

Request body

OR

Example request

{
  "model": "morph-v3-fast",
  "messages": [
    {
      "role": "user",
      "content": "<instruction>I will add error handling</instruction>\n<code>function divide(a, b) {\n  return a / b;\n}</code>\n<update>function divide(a, b) {\n  if (b === 0) throw new Error('Division by zero');\n  return a / b;\n}</update>"
    }
  ],
  "stream": false,
  "max_tokens": 150,
  "temperature": 0
}

Response

Chat completion response

idstring required

Unique identifier for the completion

objectstring required

Always chat.completion

createdinteger required

Unix timestamp of when the completion was created

Example response

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "\ndef calculate_total(items):\n    total = 0\n    for item in items:\n        total += item.price\n    return total * 1.1  # Add 10% tax\n"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 32,
    "total_tokens": 57
  }
}

Changes