# Python

Use the OpenAI Python SDK with an explicit ohgrok base URL.

<a id="install"></a>

## Install and configure

Run this example on your backend or local machine. Set OHGROK_API_KEY first. JavaScript uses Node.js and an ES module (.mjs).

```
python -m pip install openai
export OHGROK_API_KEY='YOUR_API_KEY'
```

<a id="request"></a>

## Request example

SDK examples cover text chat. Follow the dedicated endpoints for images and video.

```
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["OHGROK_API_KEY"],
    base_url="https://api.ohgrok.com/v1",
    max_retries=0,
)
response = client.chat.completions.create(
    model="grok-4.5",
    messages=[{"role": "user", "content": "Hello, ohgrok!"}],
)
print(response.choices[0].message.content)
```

<a id="result"></a>

## Read the result and handle failures

Read choices[0].message.content. Keep usage when present. SDK retries are disabled here so a beginner can inspect the first error before sending another request. Enable bounded retries only after reviewing the operation and billing behavior.

- [Error handling](/docs/errors/)
- [Official SDK source](https://github.com/openai/openai-python)

