On this page

Chat completions

POST /v1/chat/completions sends a list of messages to a model. The model writes the next message. The request and the response have the same form as the OpenAI API.

Send a request#

curl "$EMBER_API_URL/v1/chat/completions" \
  -H "Authorization: Bearer $EMBER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model ID>",
    "messages": [
      {
        "role": "system",
        "content": "You answer in one sentence."
      },
      {
        "role": "user",
        "content": "What is scale to zero?"
      }
    ],
    "temperature": 0.7,
    "max_tokens": 256
  }'

Messages#

Each message has a role and a content. A request can have up to 2,048 messages.

RoleUse
systemInstructions for the model. Put it first.
userA message from the person or your application.
assistantAn earlier answer of the model.
toolThe result of a tool call. Set tool_call_id.

The content can be text, or a list of parts. A part is text or an image. An image must be a data: URL of a PNG, JPEG or WebP file. The API refuses remote image URLs.

Sampling#

ParameterRangeEffect
temperature0 to 2Low values give focused answers. High values vary more.
top_p0 to 1Use only the most probable tokens up to this total probability.
max_tokens1 to 131,072The longest answer in tokens.
stopUp to 4 stringsThe model stops before it writes one of them.
seedAn integerThe same seed and request give similar answers.
n1 to 8The number of answers.
presence_penalty−2 to 2Positive values make new topics more likely.
frequency_penalty−2 to 2Positive values make repeated words less likely.

Change temperature or top_p, but not both.

Streaming#

Set "stream": true to get the answer in pieces. The response is a server-sent event stream. Each event is data: and a JSON chunk. The last event is data: [DONE].

To get the token counts in the stream, set "stream_options": {"include_usage": true}. For a shared model, the usage chunk also has the cost of the request.

curl "$EMBER_API_URL/v1/chat/completions" \
  -H "Authorization: Bearer $EMBER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model ID>",
    "messages": [
      {
        "role": "user",
        "content": "Count to five."
      }
    ],
    "temperature": 0.7,
    "max_tokens": 256,
    "stream": true
  }'

JSON output#

Set response_format to get JSON. Use {"type": "json_object"} for any JSON object. Use {"type": "json_schema", "json_schema": {...}} to give a schema. Also tell the model in a message that you want JSON.

Support for each format depends on the model and its runtime. Examine the answer before you use it.

Tools#

Give the model up to 128 tools in tools. Each tool is a function with a name, a description and JSON Schema parameters. The model can answer with tool_calls. Run the tool in your application. Then send the result in a message with the role tool.

json
{
  "type": "function",
  "function": {
    "name": "get_weather",
    "description": "The weather now in a city",
    "parameters": {
      "type": "object",
      "properties": { "city": { "type": "string" } },
      "required": ["city"]
    }
  }
}

Use tool_choice to let the model choose, to stop tool calls, or to require one tool.

Prompt caching#

Requests that start with the same messages are faster when they go to the same replica. Set prompt_cache_key to the same value for each request of one conversation.

On a shared model, "prompt_cache_retention": "1h" keeps the prompt in the cache for 60 minutes. You pay for each token-minute that is held. A deployment refuses this field.

Response headers#

HeaderMeaning
X-Request-IdThe ID of the request. Give it to support.
X-Ember-RegionThe region that answered.
X-Ember-Cold-Start-MsThe time that a cold start added, if there was one.
X-Ember-Cost-Micro-UsdThe cost in micro-USD. Only for a shared model without streaming.

Privacy#

Nuemetrix does not keep prompts or responses in logs. The field user is accepted for compatibility, and then dropped.