> ## Documentation Index
> Fetch the complete documentation index at: https://docs.redpill.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Agents SDK

> Use RedPill with the OpenAI Agents SDK

The OpenAI Agents SDK accepts a custom `AsyncOpenAI` client. Select its Chat Completions model
explicitly because the SDK uses the Responses API by default.

## Install

```bash theme={null}
pip install openai-agents
export REDPILL_AI_API_KEY="YOUR_API_KEY"
```

## Build an agent

```python theme={null}
import os

from agents import (
    Agent,
    OpenAIChatCompletionsModel,
    Runner,
    function_tool,
    set_tracing_disabled,
)
from openai import AsyncOpenAI


set_tracing_disabled(True)

client = AsyncOpenAI(
    base_url="https://api.redpill.ai/v1",
    api_key=os.environ["REDPILL_AI_API_KEY"],
)
model = OpenAIChatCompletionsModel(
    model="z-ai/glm-5.2",
    openai_client=client,
)


@function_tool
def deployment_status(service: str) -> str:
    """Return a sample deployment status."""
    return f"{service}: healthy"


agent = Agent(
    name="Operations assistant",
    instructions="Use the tool to check deployment status.",
    model=model,
    tools=[deployment_status],
)

result = Runner.run_sync(
    agent,
    "Check the gateway deployment status.",
    max_turns=3,
)
print(result.final_output)
```

Tracing is disabled because the default trace exporter requires an OpenAI platform key. Configure a
different trace processor when your application needs tracing.

## Production checks

Keep `max_turns` bounded, add network timeouts, and validate tool input. For confidential-only
calls, change the client base URL to `https://tee.redpill.ai/v1` and select an `is_tee: true` model.

## Troubleshooting

| Symptom                        | Check                                                       |
| ------------------------------ | ----------------------------------------------------------- |
| SDK calls the wrong API shape  | Wrap the client with `OpenAIChatCompletionsModel`.          |
| Default tracing reports errors | Disable tracing or configure a compatible trace processor.  |
| Agent runs too many turns      | Lower `max_turns` and add request limits around the runner. |

## References

* [OpenAI Agents SDK models](https://openai.github.io/openai-agents-python/models/)
* [RedPill function calling](/guides/function-calling)
