# Chat

Chat completions, compatible with the OpenAI SDKs.

`POST /v1/chat/completions`, compatible with the OpenAI SDKs. Set `"stream": true` for long answers: without streaming, the whole answer has to arrive within about 90 seconds. More: [Streaming](https://ewest.ai/docs/streaming), [Tool calling](https://ewest.ai/docs/tool-calling) and [Structured output](https://ewest.ai/docs/structured-output). To send pictures, PDFs or audio in a message, see [Files](https://ewest.ai/docs/files).

cURL:

```bash
curl https://api.ewest.ai/v1/chat/completions \
  -H "Authorization: Bearer $EWEST_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "ewest/gemini-flash", "stream": true,
       "messages": [{"role": "user", "content": "Hello!"}]}'
```

Python:

```python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.ewest.ai/v1", api_key=os.environ["EWEST_KEY"])
stream = client.chat.completions.create(
    model="ewest/gemini-flash",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
```

JavaScript:

```javascript
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.ewest.ai/v1", apiKey: process.env.EWEST_KEY });
const stream = await client.chat.completions.create({
  model: "ewest/gemini-flash",
  messages: [{ role: "user", content: "Hello!" }],
  stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
```

Source: https://ewest.ai/docs/chat
