curl -X POST https://www.blackbox.ai/api/v1/chat \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "model": "blackbox-chat",
  "messages": [
    {
      "role": "user",
      "content": "Write a short story about an astronaut."
    }
  ],
  "temperature": 0.7,
  "max_tokens": 256,
  "stream": false
}'
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "blackbox-chat",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The lone astronaut, Commander Eva, stared out at the swirling nebula..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 50,
    "total_tokens": 62
  }
}
This endpoint generates a response from the model based on a conversation history.
curl -X POST https://www.blackbox.ai/api/v1/chat \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "model": "blackbox-chat",
  "messages": [
    {
      "role": "user",
      "content": "Write a short story about an astronaut."
    }
  ],
  "temperature": 0.7,
  "max_tokens": 256,
  "stream": false
}'

Request Body

model
string
required
The ID of the model to use. See the Models page for available options.
messages
array
required
An array of message objects representing the conversation history. Each object must have a role (user or assistant) and content (the message text).
stream
boolean
Defaults to false. If set to true, the response will be streamed back in chunks as it’s generated.
max_tokens
integer
The maximum number of tokens to generate in the completion. Defaults to 1024.
temperature
number
Controls randomness. A lower value (e.g., 0.2) makes the output more deterministic, while a higher value (e.g., 0.8) makes it more random. Defaults to 1.
top_p
number
An alternative to sampling with temperature, called nucleus sampling. Defaults to 1.
agent
string
An optional parameter to specify a specialized agent for the task.
response_format
object
An object specifying the format that the model must output. Setting { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "blackbox-chat",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The lone astronaut, Commander Eva, stared out at the swirling nebula..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 50,
    "total_tokens": 62
  }
}