> ## Documentation Index
> Fetch the complete documentation index at: https://bianxieai.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a chat completion

> Generate a reply from a list of messages

Authenticate with a Bearer API key and send JSON.

| Field                                   | Type         | Required | Description                                                                                         |
| --------------------------------------- | ------------ | -------- | --------------------------------------------------------------------------------------------------- |
| `model`                                 | string       | Yes      | Model ID from the live model page.                                                                  |
| `messages`                              | array        | Yes      | Ordered system, developer, user, assistant, or tool messages; content may be text or content parts. |
| `temperature`, `top_p`                  | number       | No       | Sampling controls; normally adjust only one.                                                        |
| `max_completion_tokens`                 | integer      | No       | Maximum generated tokens.                                                                           |
| `stream`                                | boolean      | No       | Return SSE deltas. Default `false`.                                                                 |
| `stop`                                  | string/array | No       | Stop sequences, subject to model support.                                                           |
| `n`                                     | integer      | No       | Number of choices.                                                                                  |
| `presence_penalty`, `frequency_penalty` | number       | No       | Topic and repetition controls.                                                                      |
| `response_format`                       | object       | No       | Text, JSON object, or JSON Schema output.                                                           |
| `tools`, `tool_choice`                  | mixed        | No       | Tool definitions and selection policy.                                                              |
| `seed`, `user`, `metadata`              | mixed        | No       | Reproducibility hint, user ID, and metadata, subject to model support.                              |

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.bianxie.ai/v1/chat/completions \
    -H "Authorization: Bearer API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "your-model",
      "messages": [{"role": "user", "content": "Hello"}],
      "temperature": 0.7
    }'
  ```

  ```python Python theme={null}
  client.chat.completions.create(model="your-model", messages=[{"role":"user","content":"Hello"}])
  ```

  ```javascript Node.js theme={null}
  await client.chat.completions.create({ model: "your-model", messages: [{ role: "user", content: "Hello" }] });
  ```
</CodeGroup>

A non-streaming response contains `id`, `object`, `created`, `model`, `choices[]`, and `usage`. Each choice has `index`, `message`, and `finish_reason`. Streaming responses provide `choices[].delta` increments.
