Skip to content

Examples and guides for using the OpenAI API

3.3 KB
Raw Blame

Agents API examples

Complete applications and sandbox integrations for the Agents API. Each application README walks through the implementation and explains how to run it.

Applications

Example What it does
SRE bot Investigate alerts and request approval for recovery actions.
Slack bot Answer requests using conversation history and connected workplace tools.
Data analyst Answer questions with read-only warehouse queries.
GitHub issue investigator Reproduce reported bugs and prepare findings for GitHub.
Document reviewer Review invoices and contracts with policy skills and specialist agents.

Sandbox integrations

  • Application-managed: your application starts and stops the sandbox directly.
  • Webhook-managed: a deployed handler provisions the sandbox while the provider's client.py calls the Agents API.

See the sandbox overview to choose a provisioning mode.

Run an example

Run commands from the Cookbook repository root. Each example's README covers dependencies, credentials, sample inputs, and cleanup. Python entry points declare their dependencies inline for uv.

The application examples require Python 3.14. Provider examples declare their supported Python version in each script.

These examples use the official OpenAI Python SDK's client.beta.agents and sessions.stream(), available in openai>=3.13.0 on PyPI.

Create sessions with the standard client:

from openai import OpenAI

client = OpenAI()

session = client.beta.agents.sessions.create(
    agent={"model": "gpt-5.6-sol"},
    environment={"type": "self_hosted", "workspace_directory": "/workspace"},
)

The sandbox examples then start codex exec-server with the returned session.environment.id and session.environment.remote_url, stream a turn, and clean up. Async applications use AsyncOpenAI with the same client.beta.agents resources and await for requests.

Keep credentials in environment variables or the example's local .env file. Use a separate restricted OPENAI_EXECUTOR_API_KEY for sandbox execution. Follow the executor authentication requirements. The executor key needs api.agents.environments.connect, and its IP restrictions must allow requests from your sandbox's outbound network.

Documentation