# Chat Completions

> The OpenAI Chat Completions endpoint POST /v1/chat/completions, available for every model. Request examples, streaming and SDK usage.

`POST https://api.goodapi.tech/v1/chat/completions` is the most general endpoint: every model can use it, including Claude and GPT models. Requests and responses follow the OpenAI Chat Completions format.

## Request

| Header | Value |
|---|---|
| `Authorization` | `Bearer sk-...` |
| `Content-Type` | `application/json` |

Send the body in OpenAI Chat Completions format. Two fields are required:

| Field | Description |
|---|---|
| `model` | Model name; must be in the key's group. See [Models and pricing](/en/docs/models) |
| `messages` | Array of messages, each with a `role` (`system`, `user` or `assistant`) and `content` |

Common optional fields: `stream` (streaming), `max_tokens`, `temperature`, `tools`.

## Example

```bash
curl https://api.goodapi.tech/v1/chat/completions \
  -H "Authorization: Bearer $GOODAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Introduce yourself in one sentence."}
    ]
  }'
```

Response (excerpt):

```json
{
  "id": "...",
  "object": "chat.completion",
  "model": "deepseek-v4-flash",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "..."},
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 22, "completion_tokens": 18, "total_tokens": 40}
}
```

The reply text is in `choices[0].message.content`, and the usage for this request is in `usage`.

## Streaming

Add `"stream": true` to the body and the response becomes SSE. Each event is a `data: {...}` line with the content delta in `choices[0].delta`, and the stream ends with `data: [DONE]`:

```text
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

data: [DONE]
```

## Using an SDK

Python:

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["GOODAPI_API_KEY"],
    base_url="https://api.goodapi.tech/v1",
)

stream = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

Node.js:

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.GOODAPI_API_KEY,
  baseURL: "https://api.goodapi.tech/v1",
});

const response = await client.chat.completions.create({
  model: "deepseek-v4-flash",
  messages: [{ role: "user", content: "Hello" }],
});
console.log(response.choices[0].message.content);
```

## Claude and GPT models

Claude and GPT models work through this endpoint too: set `model` to the model name, and create the key in that model's group. When you need these models' native features, use the [Messages](/en/docs/messages) endpoint (Claude) or the [Responses](/en/docs/responses) endpoint (GPT) instead.
