Chat completions

Docs · API

Chat completions

Request schema, response shape, and limits for POST /v1/chat/completions.

On this page

POST /v1/chat/completions accepts an OpenAI-compatible chat body and returns either a chat.completion object or a server-sent event stream. It requires a user API key.

Request body

FieldTypeRequiredRules
modelstringYes1–200 characters. Use lfm3, the only live model key.
messagesarrayYes1–64 messages. Each has role and content.
messages[].rolestringYessystem, user, or assistant.
messages[].contentstringYes1–100,000 characters.
maxTokensintegerNo1–4,096. Defaults to 512.
max_tokensintegerNoSame as maxTokens; the OpenAI-style name is accepted.
streambooleanNotrue returns SSE; default is a single JSON response.

Unknown fields are accepted by validation but are not acted on.

The estimated input size is checked before a job is created. The gateway sums ceil(characters / 4) over all messages; an estimate above 2,048 tokens is rejected with 413 CONTEXT_LIMIT.

Non-streaming request

curl https://<your-domain>/v1/chat/completions \
  -H "Authorization: Bearer $EASYAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "lfm3",
    "messages": [
      { "role": "system", "content": "Answer concisely." },
      { "role": "user", "content": "What is a deadline in a job queue?" }
    ],
    "maxTokens": 256
  }'

Success response

{
  "id": "chatcmpl-<job-id>",
  "object": "chat.completion",
  "created": 1762560000,
  "model": "lfm3",
  "choices": [
    {
      "message": { "role": "assistant", "content": "..." },
      "index": 0,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 18,
    "completion_tokens": 42,
    "total_tokens": 60
  },
  "jobId": "<job-id>",
  "status": "COMPLETED",
  "output": "..."
}

choices[0].message.content and the additive output field contain the same answer. usage reports the tokens the gateway accounted for the request.

Job status

A non-streaming response includes jobId. You can read the lifecycle view of your own job at:

curl https://<your-domain>/v1/jobs/<job-id> \
  -H "Authorization: Bearer $EASYAI_API_KEY"

The response includes status, timestamps, failureCode, usage counters, and metric counts. Another user’s job returns 404 JOB_NOT_FOUND, the same as a missing job. Prompt and output content are not stored or returned by this endpoint.

Errors

The HTTP error body is always:

{ "error": { "code": "..." } }

Common responses for this endpoint:

StatusCodeMeaning
400VALIDATION_FAILEDThe body does not match the schema.
401UNAUTHORIZEDThe API key is missing, invalid, or inactive.
402INSUFFICIENT_CREDITSThe request cannot reserve its credit hold.
413CONTEXT_LIMITEstimated input exceeds 2,048 tokens.
429RATE_LIMITEDThe per-key request window is exhausted.
503NO_CAPACITYNo eligible worker could be reserved.
503PROMPT_HOLD_UNAVAILABLEWorker-executed mode could not stage the prompt.
504DEADLINE_EXCEEDEDThe job deadline passed.
504STAGE_TIMEOUTA pipeline stage exceeded its deadline.
500INTERNALUnexpected gateway or execution failure.

See Errors for the full code list and Streaming for the SSE variant.

Docs menu