# OpenAI-Compatible API

samreshuuu exposes a drop-in `chat/completions` endpoint. If you already use the OpenAI SDK, change the base URL and the API key — nothing else.

- **Base URL:** `https://api.samreshuuu.com/v1`
- **Auth:** an API key with the `chat` scope (see [Authentication](/docs/authentication))

## Drop-In Example

**Python**

```python
from openai import OpenAI

client = OpenAI(
    api_key="sk-org-your_api_key",
    base_url="https://api.samreshuuu.com/v1",
)

resp = client.chat.completions.create(
    model="samreshuuu",
    messages=[{"role": "user", "content": "Summarize this contract"}],
)
print(resp.choices[0].message.content)
```

**Node.js**

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk-org-your_api_key",
  baseURL: "https://api.samreshuuu.com/v1",
});

const resp = await client.chat.completions.create({
  model: "samreshuuu",
  messages: [{ role: "user", content: "Summarize this contract" }],
});
console.log(resp.choices[0].message.content);
```

**cURL**

```bash
curl https://api.samreshuuu.com/v1/chat/completions \
  -H "Authorization: Bearer sk-org-your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "samreshuuu",
    "messages": [{"role": "user", "content": "Summarize this contract"}]
  }'
```

**About the model field**

The `model` parameter is required by the OpenAI SDK but ignored by the server — the platform selects the model. Pass any placeholder string. Sampling parameters such as `temperature` and `max_tokens` are accepted for compatibility but not honored on this endpoint.

## Request Fields

<ParamTable
    rows={[
        { name: "messages", type: "array", required: true, description: "Chat messages. The last user message drives the turn; earlier messages are treated as history." },
        { name: "stream", type: "boolean", description: "When true, stream OpenAI chat.completion.chunk frames. Default false." },
        { name: "session_id", type: "string", description: "Reuse a session_id to continue a prior conversation. Omit to start fresh." },
        { name: "max_iterations", type: "integer", description: "Agent loop cap, 1–50. Default 25." },
        { name: "stream_options", type: "object", description: "Streaming extras. Set { \"include_tool_progress\": true } to also receive named tool.progress SSE events. Off by default." },
    ]}
/>

**This key acts on the full seller account**

A `chat` API key drives the same agent as the workspace — the model can reach the entire tool registry, including connectors to the seller's cabinet and the `terminal` tool. Treat the key like account credentials: scope it per integration, store it server-side only, and rotate it if exposed. There is no read-only mode on this endpoint.

## Streaming

Set `stream: true` to receive Server-Sent Events in OpenAI's chunk format, terminated by a final `data: [DONE]` frame.

```bash
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Here"},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
```

### Tool progress (opt-in)

Pass `stream_options: { "include_tool_progress": true }` (or the header `X-Hermes-Tool-Progress: 1`) to receive named `tool.progress` SSE events interleaved with the standard chunks. They live on a separate event channel, so strict OpenAI clients that only read `chat.completion.chunk` ignore them — and never persist them into history. When the option is off the byte stream is identical to a vanilla OpenAI response.

```bash
event: tool.progress
data: {"type":"tool.started","tool_name":"connector","label":"MoySklad","iteration":1}

event: tool.progress
data: {"type":"tool.completed","tool_name":"connector","label":"MoySklad","success":true,"duration_ms":842}
```

**Multi-turn**

Pass the same `session_id` across requests to keep context. The first response creates the session; reuse its id on the next call.
