Basic Chat Completions

Overview

Basic chat completions allow you to send a message and receive a response from the model. This is the simplest way to interact with the LLM Gateway.

Getting started

Send a message and receive a response:

1import requests
2
3headers = {
4 "authorization": "<YOUR_API_KEY>"
5}
6
7response = requests.post(
8 "https://llm-gateway.assemblyai.com/v1/chat/completions",
9 headers = headers,
10 json = {
11 "model": "claude-sonnet-4-5-20250929",
12 "messages": [
13 {"role": "user", "content": "What is the capital of France?"}
14 ],
15 "max_tokens": 1000
16 }
17)
18
19result = response.json()
20print(result["choices"][0]["message"]["content"])

API reference

Request

The LLM Gateway accepts POST requests to https://llm-gateway.assemblyai.com/v1/chat/completions with the following parameters:

$curl -X POST \
> "https://llm-gateway.assemblyai.com/v1/chat/completions" \
> -H "Authorization: YOUR_API_KEY" \
> -H "Content-Type: application/json" \
> -d '{
> "model": "claude-sonnet-4-5-20250929",
> "messages": [
> {
> "role": "user",
> "content": "What is the capital of France?"
> }
> ],
> "max_tokens": 1000
> }'

Request parameters

KeyTypeRequired?Description
modelstringYesThe model to use for completion. See Available models section for supported values.
messagesarrayYes*An array of message objects representing the conversation history. Either messages or prompt is required.
promptstringYes*A simple string prompt for single request/response interactions. Either messages or prompt is required.
max_tokensnumberNoThe maximum number of tokens to generate. Range: [1, context_length).
temperaturenumberNoControls randomness in the output. Higher values make output more random. Range: [0, 2].

Message object

KeyTypeRequired?Description
rolestringYesThe role of the message sender. Valid values: "user", "assistant", "system", or "tool".
contentstring or arrayYesThe message content. Can be a string or an array of content parts for the "user" role.
namestringNoAn optional name for the message sender. For non-OpenAI models, this will be prepended as {name}: {content}.

Content part object

KeyTypeRequired?Description
typestringYesThe type of content. Currently only "text" is supported.
textstringYesThe text content.

Response

The API returns a JSON response with the model’s completion:

1{
2 "request_id": "abc123",
3 "choices": [
4 {
5 "message": {
6 "role": "assistant",
7 "content": "The capital of France is Paris."
8 },
9 "finish_reason": "stop"
10 }
11 ],
12 "request": {
13 "model": "claude-sonnet-4-5-20250929",
14 "max_tokens": 1000
15 },
16 "usage": {
17 "prompt_tokens": 15,
18 "completion_tokens": 8,
19 "total_tokens": 23
20 }
21}

Response fields

KeyTypeDescription
request_idstringA unique identifier for the request.
choicesarrayAn array of completion choices. Typically contains one choice.
choices[i].messageobjectThe message object containing the model’s response.
choices[i].message.rolestringThe role of the message, typically "assistant".
choices[i].message.contentstringThe text content of the model’s response.
choices[i].finish_reasonstringThe reason the model stopped generating. Common values: "stop", "length".
requestobjectEcho of the request parameters (excluding prompt and messages).
usageobjectToken usage statistics for the request.
usage.prompt_tokensnumberNumber of tokens in the prompt.
usage.completion_tokensnumberNumber of tokens in the completion.
usage.total_tokensnumberTotal tokens used (prompt + completion).

Error response

If an error occurs, the API returns an error response:

1{
2 "error": {
3 "code": 400,
4 "message": "Invalid request: missing required field 'model'",
5 "metadata": {}
6 }
7}
KeyTypeDescription
errorobjectContainer for error information.
error.codenumberHTTP status code for the error.
error.messagestringA human-readable description of the error.
error.metadataobjectOptional additional error context.

Common error codes

CodeDescription
400Bad Request - Invalid request parameters
401Unauthorized - Invalid or missing API key
403Forbidden - Insufficient permissions
404Not Found - Invalid endpoint or model
429Too Many Requests - Rate limit exceeded
500Internal Server Error - Server-side error