API referenceAdvanced usersUpdated
POST/v1/chat/completions

API console

POST/v1/chat/completions
View keys

Requests use the API key you enter and follow standard API billing.

Chat Completions

Send a conversation using the OpenAI Chat format. Check that your model and selected endpoint support the Chat protocol before sending the request.

Before you start

Follow the quickstart to get an API key and select an endpoint that accepts direct HTTP calls. The example reads the Bearer token from ICODEEASY_API_KEY. Replace YOUR_MODEL_ID with a model ID supported by your endpoint.

Request example

Set model to your model ID and put the conversation in messages. Use stream: false to request JSON.

bash
curl -sS https://api.icodeeasy.cc/v1/chat/completions \
  -H "Authorization: Bearer $ICODEEASY_API_KEY" \
  -H 'Content-Type: application/json' \
  --data '{
  "model": "YOUR_MODEL_ID",
  "messages": [
    {
      "role": "user",
      "content": "Say hello."
    }
  ],
  "stream": false
}'

Read the response

Read text from choices[].message.content. The usage object can include prompt_tokens, completion_tokens, and total_tokens. When present, usage.prompt_tokens_details.cached_tokens counts cached input tokens.

json
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Hello!"
      },
      "finish_reason": "stop"
    }
  ]
}

Streaming response example

Set stream: true in the request body to receive SSE. In SSE, accumulate delta.content separately for each choices[].index. Record each choice's finish_reason and keep reading for a final usage chunk or [DONE]. An error frame or a disconnect before any completion signal leaves the result failed or incomplete.

text
data: {"choices":[{"index":0,"delta":{"content":"Hello!"},"finish_reason":null}]}

data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: {"choices":[],"usage":{"prompt_tokens":10,"completion_tokens":4,"total_tokens":14}}

data: [DONE]

For endpoints that support streaming usage, request stream_options.include_usage: true. A usage-only chunk may have empty choices.