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

# OpenAI SDK setup

> Use Chat Completions with the OpenAI Python SDK.

## Before you start

Complete organization setup, make sure your account has inference credit, and create a key on the [API Keys page](https://platform.pearlresearch.ai/api-keys). Most coding agents need a tool-capable chat model; Aider's basic edit workflow does not require native tool calling. Image input and reasoning support depend on the model. These terminal examples use Bash or Zsh on macOS, Linux, or Windows through WSL.

You need Python 3.10 or later and pip to run the SDK examples below. Install the package in the Python environment you use for your application.

## Get your connection settings

Open [Integrations](https://platform.pearlresearch.ai/integrations), select a model, then choose OpenAI SDK. The screen uses your organization's region. The examples below use the public global endpoint; replace it with your regional endpoint and replace `YOUR_MODEL_ID` with the full model ID shown there. Choose one of the models listed for this integration.

Set your Pearl API key in the terminal where you run OpenAI SDK:

```bash theme={null}
export PEARL_API_KEY="YOUR_PEARL_API_KEY"
```

## Configure OpenAI SDK

Save the Python example as `pearl_example.py` in this directory.

```bash Install theme={null}
python3 -m pip install openai
```

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

client = OpenAI(
    base_url="https://inference.pearlresearch.ai/v1",
    api_key=os.environ["PEARL_API_KEY"],
)
response = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Hello!"}],
    max_tokens=8192,  # covers the reasoning and the answer
    # Levels the model does not serve round up to the next one it does (GET /models lists them).
    # Send {"effort": "none"} to turn reasoning off (models marked mandatory return 400).
    extra_body={"reasoning": {"effort": "high"}},
)
message = response.choices[0].message
if getattr(message, "reasoning", None):
    print("Thinking:", message.reasoning)
print(message.content)
```

Run the saved example in the same terminal where you set your API key:

```bash theme={null}
python3 pearl_example.py
```

A successful run prints a model reply.

## Set reasoning effort

The examples set the effort with `extra_body={"reasoning": {"effort": "high"}}`, which the SDK merges into Pearl's request body as `reasoning.effort`, and `{"effort": "none"}` turns thinking off. Use this instead of the top-level `reasoning_effort` parameter, which returns `400`.

Accepted levels are `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`. The set a model actually serves is `supported_efforts` in its `reasoning` block on [GET /models](/docs/reference/models.md); any other level rounds up to the next served one, or to the highest past the top ([how levels map](/docs/reasoning.md#effort-mapping)). Omit the field for the model's default, which is `max` on GLM-5.3, so set it explicitly for agents and pipelines. GLM-5.3 and GLM-5.3-Flash always reason and return `400` on the off switch. The output token limit covers the reasoning and the answer. Streaming requests include `stream_options={"include_usage": true}` so the client receives token usage.

## Stream a reply

Save this example as `pearl_stream.py` to print text as it arrives:

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

client = OpenAI(
    base_url="https://inference.pearlresearch.ai/v1",
    api_key=os.environ["PEARL_API_KEY"],
)
with client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Hello!"}],
    max_tokens=8192, stream=True,
    stream_options={"include_usage": True},
    # Levels the model does not serve round up to the next one it does (GET /models lists them).
    # Send {"effort": "none"} to turn reasoning off (models marked mandatory return 400).
    extra_body={"reasoning": {"effort": "high"}},
) as stream:
    for chunk in stream:
        if chunk.choices:
            print(chunk.choices[0].delta.content or "", end="", flush=True)
        if chunk.usage:
            print("\nUsage:", chunk.usage)
```

```bash theme={null}
python3 pearl_stream.py
```

## Start using OpenAI SDK

Replace the example prompt with your own request. You can review token usage and costs on the [Analytics page](https://platform.pearlresearch.ai/usage).

## Troubleshooting

* `401`: check the key and allow time for a newly created key to reach the inference gateway.
* `404`: copy the endpoint and exact model ID from Integrations. OpenAI base URLs end in `/v1`; the Anthropic SDK and Claude Code use the URL without that suffix.
* `402`: check your organization's credit and billing status.
* `429` or Anthropic `529`: respect retry instructions and reduce concurrency.
* For truncated output, check the output limit and reasoning budget. Increase limits only within the model's maximum output length.
* If pip is missing or reports `externally-managed-environment`, follow the [Python package installation guide](https://packaging.python.org/en/latest/tutorials/installing-packages/) for your Python installation, then use that same interpreter to install the SDK and run the example.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.