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

# OpenAI SDK

> Use RedPill through the OpenAI SDK, with optional local ACI verification on Node and Bun.

RedPill supports the OpenAI SDK's Responses, Chat Completions, and Embeddings resources. Set the
base URL to `https://api.redpill.ai/v1` and use an exact RedPill model ID.

<Warning>
  Changing only the base URL does not make the SDK a local ACI verifier.
</Warning>

<CodeGroup>
  ```bash Python theme={null}
  pip install openai
  ```

  ```bash TypeScript theme={null}
  npm install openai
  ```
</CodeGroup>

```bash theme={null}
export REDPILL_AI_API_KEY="YOUR_API_KEY"
```

## Responses

<CodeGroup>
  ```python Python theme={null}
  import os

  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ["REDPILL_AI_API_KEY"],
      base_url="https://api.redpill.ai/v1",
  )
  response = client.responses.create(
      model="z-ai/glm-5.2",
      input="Explain attestation in one sentence.",
  )
  print(response.output_text)
  ```

  ```typescript TypeScript theme={null}
  import OpenAI from "openai";

  const apiKey = process.env.REDPILL_AI_API_KEY;
  if (!apiKey) throw new Error("REDPILL_AI_API_KEY is required");

  const client = new OpenAI({
    apiKey,
    baseURL: "https://api.redpill.ai/v1",
  });
  const response = await client.responses.create({
    model: "z-ai/glm-5.2",
    input: "Explain attestation in one sentence.",
  });
  console.log(response.output_text);
  ```
</CodeGroup>

## Chat Completions

Use Chat Completions when an existing application expects that API shape:

```typescript theme={null}
const response = await client.chat.completions.create({
  model: "z-ai/glm-5.2",
  messages: [{ role: "user", content: "Reply with: connected" }],
});
console.log(response.choices[0]?.message.content);
```

Pass `stream=True` in Python or `stream: true` in TypeScript for server-sent events. See
[Streaming](/guides/streaming) and [Function calling](/guides/function-calling) for complete loops.

## Embeddings

Embedding models use a separate catalog:

```bash theme={null}
curl -s https://api.redpill.ai/v1/embeddings/models \
  | jq -r '.data[] | [.id, .is_tee, .context_length] | @tsv'
```

```python theme={null}
response = client.embeddings.create(
    model="qwen/qwen3-embedding-8b",
    input="Receipts bind requests and responses to the serving path.",
)
embedding = response.data[0].embedding
```

## Verified Node and Bun transport

Node 20.18+ and Bun 1.4+ can inject the same ACI runtime `fetch`:

```bash theme={null}
npm install openai @phala/aci-verifier
```

```typescript theme={null}
import OpenAI from "openai";
import { connectAci } from "@phala/aci-verifier/runtime";

const apiKey = process.env.REDPILL_AI_API_KEY;
if (!apiKey) throw new Error("REDPILL_AI_API_KEY is required");

const aci = await connectAci({
  baseURL: "https://tee.redpill.ai/v1",
  policy: { requireProductionOs: true },
  serving: { requireVerified: true, requireReceipt: true },
});

try {
  const client = new OpenAI({ apiKey, baseURL: aci.baseURL, fetch: aci.fetch });
  const response = await client.chat.completions.create({
    model: "z-ai/glm-5.2",
    messages: [{ role: "user", content: "Explain attestation briefly." }],
  });

  const audit = await aci.verifyReceipt();
  if (!audit.transcript.verdict.verified) {
    throw new Error(audit.transcript.verdict.line);
  }
  console.log(response.choices[0]?.message.content);
} finally {
  await aci.close();
}
```

The connection verifies the TDX quote, measured compose, identity expiry, hostname, and attested TLS
SPKI before model traffic. `verifyReceipt()` checks the latest retained exchange, signed receipt,
wire hashes, and cited session.

Add `acceptedComposeHashes` only from authenticated release metadata. Without that allowlist, the
client verifies the measured hardware workload but does not claim that RedPill reviewed the release.

## Production checks

Use `https://tee.redpill.ai/v1` only with an `is_tee: true` model when standard upstreams must be
rejected. Set timeouts and bounded retries, and do not expose raw upstream errors to users.

## References

* [OpenAI Python SDK](https://github.com/openai/openai-python)
* [OpenAI TypeScript SDK](https://github.com/openai/openai-node)
* [Verify a response](/guides/verify-a-response)
* [RedPill Responses API](/api-reference/responses)
