Integrations / OpenAI Python SDK
ConnectDocumented
Use Badgr with the OpenAI Python SDK
Change base_url and the key in the official OpenAI Python client. The rest of your code stays the same.
The steps follow the tool's documented settings. No tested run is recorded for this page yet.
Why use Badgr for OpenAI Python SDK
- Badgr interface
- AI API
- Where OpenAI Python SDK fits
- External SDK
- Why Badgr
- Compatible Python inference
- Change base_url and the key. The rest of your OpenAI code, including streaming and error handling, stays.
- Billed per request at the rate listed for the model.
- The same account runs GPU jobs when a script needs more than an API call.
What you can do
- Move an existing Python app to Badgr with a two-line change
- Stream responses to a terminal or web client
- Handle rate limits and errors with the SDK's built-in exceptions
Quickstart: Python streaming request
import os
from openai import OpenAI, APIStatusError
client = OpenAI(base_url="https://aibadgr.com/v1", api_key=os.environ["BADGR_API_KEY"])
try:
stream = client.chat.completions.create(
model="badgr-auto",
messages=[{"role": "user", "content": "Say hello."}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
except APIStatusError as err:
print(f"Request failed: {err.status_code}")How it works
- 1.Your code builds an OpenAI client with the Badgr base URL
- 2.The SDK sends the request to Badgr
- 3.Chunks stream back and print as they arrive
What you get
- Chat completions and streamed text
Requirements
- A Badgr API key, saved as BADGR_API_KEY (get one at /get-api-key)
- Python 3.8 or newer
- The openai package
What it costs
- AI requests are billed per request at the rate listed for the model you choose (see Models). This page does not quote a fixed price.
- Your application keeps control of how many requests it sends. Use the limits in your own tool to cap usage.
See pricing for how billing works.
Proof
No tested run is recorded for this integration yet. A receipt and example output will be added here after a real run, not before.
Troubleshooting
Still calling OpenAI
An OPENAI_BASE_URL environment variable or a second client may be overriding your code. Print client.base_url.
AuthenticationError
The key must be your Badgr key, not an OpenAI key.
429 rate limit
The SDK retries a few times by default. For heavier use, lower your request rate or add your own backoff.
Developer reference
Ready to start with OpenAI Python SDK?
Every run or service has a spending limit you set before it starts.