Skip to main content
POST
/
v1
/
chat
/
completions
Create a chat completion
curl --request POST \
  --url https://tokens.flex.ai/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "Qwen/Qwen2.5-32B-Instruct",
  "messages": [
    {
      "role": "system",
      "content": "<string>",
      "name": "<string>",
      "tool_calls": [
        {}
      ],
      "tool_call_id": "<string>"
    }
  ],
  "stream": false,
  "stream_options": {
    "include_usage": true
  },
  "temperature": 1,
  "top_p": 0.5,
  "max_tokens": 2,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "<string>",
        "description": "<string>",
        "parameters": {}
      }
    }
  ],
  "tool_choice": "none",
  "response_format": {
    "type": "text"
  },
  "seed": 123,
  "stop": "<string>",
  "user": "<string>"
}
'
{
  "id": "<string>",
  "object": "chat.completion",
  "created": 123,
  "model": "<string>",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "<string>",
        "content": "<string>",
        "tool_calls": [
          {}
        ]
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123,
    "cache_read_input_tokens": 123,
    "cache_creation_input_tokens": 123
  }
}

Authorizations

Authorization
string
header
required

Virtual API key. Create one from the FlexAI dashboard. Pass as Authorization: Bearer sk-xxxx.

Body

application/json
model
string
required

Model id. See GET /v1/models for available models.

Example:

"Qwen/Qwen2.5-32B-Instruct"

messages
object[]
required
stream
boolean
default:false
stream_options
object
temperature
number
default:1
Required range: 0 <= x <= 2
top_p
number
Required range: 0 <= x <= 1
max_tokens
integer
Required range: x >= 1
tools
object[]
tool_choice
Available options:
none,
auto,
required
response_format
object
seed
integer
stop
user
string

Response

Successful response. When stream: true, body is an SSE stream of text/event-stream chunks.

id
string
required
object
enum<string>
required
Available options:
chat.completion
created
integer
required
model
string
required
choices
object[]
required
usage
object