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

# OpenAI SDKs

> Use Prism through the official OpenAI JavaScript and Python clients

# OpenAI SDKs

Prism's chat, embeddings, and model-list endpoints use OpenAI-compatible request
and response shapes. Set the SDK base URL to Prism and use your Prism API key.

Set `PRISM_MODEL` to a chat-capable model before running the examples. The
[Quickstart](/quickstart) intersects the public trial allowlist with the
authenticated catalog and exports a model that the key can call. For paid or
organization keys, use a chat model approved for that key. Do not select a model
by position from `/v1/models`, because the catalog can include chat, embedding,
image, and video models.

<CodeGroup>
  ```typescript JavaScript theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: process.env.PRISM_API_KEY,
    baseURL: "https://api.prismgateway.io/v1",
  });

  const model = process.env.PRISM_MODEL;
  if (!model) throw new Error("Set PRISM_MODEL to an approved chat model.");

  const response = await client.chat.completions.create({
    model,
    messages: [{ role: "user", content: "Explain this API in one sentence." }],
  });

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

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

  client = OpenAI(
      api_key=os.environ["PRISM_API_KEY"],
      base_url="https://api.prismgateway.io/v1",
  )

  model = os.environ["PRISM_MODEL"]

  response = client.chat.completions.create(
      model=model,
      messages=[{"role": "user", "content": "Explain this API in one sentence."}],
  )

  print(response.choices[0].message.content)
  ```
</CodeGroup>

## Streaming

Set `stream: true` as you would with OpenAI:

```typescript theme={null}
const stream = await client.chat.completions.create({
  model,
  messages: [{ role: "user", content: "Count from one to five." }],
  stream: true,
});

for await (const event of stream) {
  process.stdout.write(event.choices[0]?.delta.content ?? "");
}
```

## Images and video

Image requests follow an OpenAI-style endpoint, but provider-specific image
options may differ by model. Video is asynchronous and uses Prism's
`/v1/video/generations` job API. Use the HTTP examples in [Images and
video](/media) for those modalities.

[อ่านภาษาไทย](/th/sdks)
