Install a client and provide the key through the environment.
- Create an API key in the BrokenGPT dashboard and copy it once.
- Install a current OpenAI-compatible Python client with pip install openai.
- Set BROKENGPT_API_KEY in the server process or secret manager, never in committed code.
ENVIRONMENT
# PowerShell
$env:BROKENGPT_API_KEY="your-key"
# bash / zsh
export BROKENGPT_API_KEY="your-key"Send one non-streamed request first.
The base URL ends at /v1 and the public model alias is broken-one. A non-streamed call is the easiest way to validate authentication, request fields, and response parsing.
PYTHON
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["BROKENGPT_API_KEY"],
base_url="https://brokengpt.com/v1",
)
response = client.chat.completions.create(
model="broken-one",
messages=[{"role": "user", "content": "Explain SSE in three sentences."}],
)
print(response.choices[0].message.content)Stream text only after the basic call succeeds.
The chat-completions route streams server-sent events. Your client should tolerate empty deltas, inspect finish reasons, stop cleanly on completion, and handle a connection that closes before the terminal event.
PYTHON STREAM
stream = client.chat.completions.create(
model="broken-one",
messages=[{"role": "user", "content": "Write a short launch checklist."}],
stream=True,
)
for chunk in stream:
text = chunk.choices[0].delta.content if chunk.choices else None
if text:
print(text, end="", flush=True)Add bounded retries, timeouts, and application validation.
- Do not retry malformed requests or invalid credentials.
- Retry 429 and temporary 5xx responses with exponential backoff, jitter, and a maximum attempt count.
- Log the returned request ID without logging the API key or sensitive prompt content.
- Validate tool arguments and structured output before using them.
- Set application timeouts and propagate cancellation when the caller disconnects.