# OpenAI SDKs

> Use the official OpenAI Python and TypeScript SDKs by changing the base URL.

Source: https://www.lyber.ai/docs/integrations/sdks/openai/ · Markdown: https://www.lyber.ai/docs/md/integrations/sdks/openai.md

## Install

Python (`terminal`):

```bash
pip install openai
```

TypeScript (`terminal`):

```bash
npm install openai
```

## Configure the client

Python (`main.py`):

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://lyber-paid-acceptance-gateway-production.up.railway.app/v1",
    api_key=os.environ["LYBER_API_KEY"],
)
```

TypeScript (`main.ts`):

```ts
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://lyber-paid-acceptance-gateway-production.up.railway.app/v1",
  apiKey: process.env.LYBER_API_KEY,
});
```

## Send a request

Python (`main.py`):

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://lyber-paid-acceptance-gateway-production.up.railway.app/v1",
    api_key=os.environ["LYBER_API_KEY"],
)

response = client.chat.completions.create(
    model="minimax-m3.1-flash-abliterated",
    messages=[{"role": "user", "content": "Explain abliteration in two sentences."}],
    max_tokens=1024,
)
print(response.model)
print(response.choices[0].message.content)
```

TypeScript (`main.ts`):

```ts
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://lyber-paid-acceptance-gateway-production.up.railway.app/v1",
  apiKey: process.env.LYBER_API_KEY,
});

const response = await client.chat.completions.create({
  model: "minimax-m3.1-flash-abliterated",
  messages: [{ role: "user", content: "Explain abliteration in two sentences." }],
  max_tokens: 1024,
});
console.log(response.model);
console.log(response.choices[0].message.content);
```

curl (`request.sh`):

```bash
curl https://lyber-paid-acceptance-gateway-production.up.railway.app/v1/chat/completions \
  -H "Authorization: Bearer $LYBER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "minimax-m3.1-flash-abliterated",
    "messages": [{"role": "user", "content": "Explain abliteration in two sentences."}],
    "max_tokens": 1024
  }'
```

## Lyber-only fields

Fields that aren't part of the OpenAI schema, such as `max_cost_micro_usdc` or `thinking_token_budget`, go in `extra_body` in Python. In TypeScript, add them to the request object.

## Retries

The OpenAI SDKs retry some failed requests by default. Lyber never deduplicates requests, so a retried request can run, and bill, twice. Set `max_retries=0` (Python) or `maxRetries: 0` (TypeScript) and retry yourself, only on `429` with `x-lyber-admission: not-admitted` or on errors returned before the request started.
