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

# OpenAI Integration

ActGuard patches OpenAI transport methods to capture usage and enforce budget scopes.

## Requirements

| Requirement  | Version    |
| ------------ | ---------- |
| `openai` SDK | `>=1.76.0` |
| Python       | `>=3.9`    |

```bash theme={null}
pip install "openai>=1.76.0"
```

## Patched methods

* `openai._base_client.SyncAPIClient.request`
* `openai._base_client.AsyncAPIClient.request`

## Usage with ActGuard runtime

```python theme={null}
import actguard
import openai

client = actguard.Client.from_env()
oai = openai.OpenAI()

with client.run(user_id="alice", run_id="run-openai"):
    with client.budget_guard(usd_limit=0.10) as guard:
        response = oai.chat.completions.create(
            model="gpt-4o",
            messages=[{"role": "user", "content": "Hello"}],
        )

print(guard.tokens_used, guard.usd_used)
```

## Streaming behavior

For `/chat/completions` streaming calls, ActGuard injects:

```json theme={null}
{"stream_options": {"include_usage": true}}
```

This enables final usage extraction without changing application code.

The Responses API is also tracked (streaming and non-streaming).
