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

# Use the OpenAI-compatible chat endpoint

> Point an OpenAI SDK at Flowyte with a base-URL swap and talk to your agent — no new client to learn.

Flowyte exposes an **OpenAI-compatible** chat completions endpoint. If your code already uses
an OpenAI client library, you can talk to a Flowyte agent by changing two things: the base URL
and the model. The `model` is your **agent id**, and the agent's knowledge, skills, and
guardrails all apply to the response. All paths are relative to
`https://builder.flowyte.com/api/v1`.

<Note>
  Authenticate with your secret key `Authorization: Bearer flowyte_sk_…` (scope `chat:write`). This endpoint serves the agent's **published**
  version.
</Note>

## What you'll use

| Action              | Endpoint                 | Scope        |
| ------------------- | ------------------------ | ------------ |
| Create a completion | `POST /chat/completions` | `chat:write` |

## The base-URL swap

Set the client's base URL to `https://builder.flowyte.com/api/v1`, the API key to your
`flowyte_sk_…`, and pass the agent id as `model`. The SDK appends `/chat/completions` for you.

<CodeGroup>
  ```ts Node theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: process.env.FLOWYTE_API_KEY,            // flowyte_sk_…
    baseURL: "https://builder.flowyte.com/api/v1",  // ← the only swap
  });

  const completion = await client.chat.completions.create({
    model: "agt_123",                                // ← your agent id
    messages: [{ role: "user", content: "Do you ship to Canada?" }],
  });

  console.log(completion.choices[0].message.content);
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="flowyte_sk_…",
      base_url="https://builder.flowyte.com/api/v1",  # ← the only swap
  )

  resp = client.chat.completions.create(
      model="agt_123",                                 # ← your agent id
      messages=[{"role": "user", "content": "Do you ship to Canada?"}],
  )
  print(resp.choices[0].message.content)
  ```

  ```bash curl theme={null}
  curl https://builder.flowyte.com/api/v1/chat/completions \
    -H "Authorization: Bearer $FLOWYTE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "agt_123",
      "messages": [{ "role": "user", "content": "Do you ship to Canada?" }]
    }'
  ```
</CodeGroup>

The response is the standard completion shape: read the reply from
`choices[0].message.content`.

## Streaming

Set `stream: true` and the endpoint returns OpenAI-style SSE chunks —
`data: {choices:[{delta:{content}}]}` … terminated by `data: [DONE]` — so an OpenAI SDK's
streaming mode works unchanged.

```ts theme={null}
const stream = await client.chat.completions.create({
  model: "agt_123",
  messages: [{ role: "user", content: "Summarize your return policy." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
```

## What's read, and what isn't

* Only `model`, `messages`, `stream`, and `user` are used. The agent's own configuration
  governs its behavior — sampling, tools, and system prompt come from the published agent, so
  request-level overrides for those are ignored.
* `model` must be a real agent id, not an OpenAI model name. An unknown id returns a `400`.
* Roles `system`, `user`, `assistant`, and `tool` are accepted in `messages`.

<Tip>
  Need session state, tool-call events, or quick replies? Use the native chat API instead:
  `POST /chat/sessions` then `POST /chat/sessions/{id}/messages` with `stream: true`. For an
  in-browser widget, mint a publishable key — see [Embed the chat widget](/guides/embed-chat-widget).
</Tip>

Related: [Agents](/concepts/agents) · [Authentication](/get-started/authentication)
