Docs Start
Quickstart: Python
Record one OpenAI call from a Python script as a Runback run, then open it in the app. About five minutes.
Before you begin
- A Runback account. Create one free.
- Python 3.9 or later. Check with
python3 --version. - An OpenAI API key, set as
OPENAI_API_KEY. No OpenAI key? Step 4 has a test command that needs none.
Steps
Get a Runback key
A key tells Runback which workspace a run belongs to. Use a Send only key: it can send runs and nothing else.In the app, open Settings › Keys and access › API key, keep Send only selected, select Generate API key and copy it. It is shown once, and starts
rb_cloud_. Creating keys needs a workspace admin; whoever created the workspace is one.Checking your session…
Install the SDK
Install Runback's Python SDK with the OpenAI extra, which also installs the OpenAI client. A virtual environment is recommended.
terminalShell pip install "runback-sdk[openai]"Expected outputpip ends with a
Successfully installedline and no errors.Put your key in your shell
Runback's SDKs and the test script read the key from the
RUNBACK_API_KEYenvironment variable. Replace the placeholder with the key from step 1. If you signed in, step 1 has already filled it in.terminalShell export RUNBACK_API_KEY="<RUNBACK_API_KEY>"Expected outputNothing is printed. To check it is set, run
echo $RUNBACK_API_KEY; it should print your key, startingrb_cloud_.Record a model call
Save this as
agent.pyand run it withOPENAI_API_KEYset. It makes one OpenAI call through the wrapped client, so the call is recorded as a run namedquickstart-agent.agent.pyPython # agent.py: run with OPENAI_API_KEY=sk-... python agent.py import openai from runback import Collector from runback.openai import wrap_openai task = "Say hello in three words." run = Collector(run_name="quickstart-agent", input=task) client = wrap_openai(openai.OpenAI(), run) res = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": task}], ) answer = res.choices[0].message.content run.finish(output=answer) print(answer)terminalShell OPENAI_API_KEY=sk-... python agent.pyExpected outputThe model's short reply, for example
Hello there, friend.and nothing else. A line starting[runback]means the run was not sent: see Troubleshooting below.No OpenAI key? Skip this step and send a test run instead. It uses the
RUNBACK_API_KEYyou exported and installs nothing.terminalShell curl -fsSL https://runback.dev/api/quickstart | bashCheck the run arrived
Open Runs in the app. Your run is at the top, named
quickstart-agent. Open it to step through what the agent did.
Troubleshooting
| You see | What it means | Fix |
|---|---|---|
[runback] no RUNBACK_API_KEY set — dropped 3 events | The key is not set in the terminal you ran the agent from. | Run step 3 again in the same terminal (a new terminal tab starts without it), then run the agent again. |
[runback] ingest failed 401 {"error":"Invalid API key"} | Runback rejected the key: mistyped, revoked or expired. | Copy the whole key again, or create a new one in Settings › Keys and access › API key. |
ModuleNotFoundError: No module named 'runback' | The package went into a different Python environment. | Activate the virtual environment you installed into, or run python -m pip install "runback-sdk[openai]" with the same python you run the agent with. |
openai.OpenAIError: Missing credentials | OPENAI_API_KEY is not set. | Run the agent as OPENAI_API_KEY=sk-... python agent.py, or use the test-run command under step 4. |
| The agent printed its reply but the run is not in Runs | The key belongs to a different workspace, or you are looking at the shared demo. | Check the workspace name in the top right of the app is the one the key came from. |
Your agent never fails because of Runback: if recording fails, the model call still returns and Runback prints one [runback] line saying why.
What the wrapper records
wrap_openai records chat.completions and responses calls, sync or async, streamed or not. Tool results you send back in the next request become tool steps paired with the model's call. Your model call is unchanged: errors are recorded, then re-raised. Redaction runs inside your process before anything is sent.
Next steps
- Anthropic, LangGraph or the OpenAI Agents SDK? See Integrations.
- See what the run you sent contains: Capture.
- Stop a risky tool call before it runs: pass
decide=TruetoCollector; see Control.