> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Auth

> Authenticate AgentOSClient calls with the central OS security key.

```python auth.py theme={null}
"""Authenticate AgentOSClient calls with the central OS security key.

Start ``_server.py`` with OS_SECURITY_KEY set, then run this file with the same
value. See lesson ``07_security`` in Phase 2 for JWT, RBAC, and service-account
authentication.

Prerequisites: start ``_server.py`` with OS_SECURITY_KEY and OPENAI_API_KEY.
Run: .venvs/demo/bin/python cookbook/05_agent_os/03_python_client/06_auth.py
Try: remove the Authorization header and observe the server return HTTP 401.
"""

import asyncio
import os

from agno.client import AgentOSClient

BASE_URL = "http://localhost:7778"
AGENT_ID = "assistant"


# ---------------------------------------------------------------------------
# Create the Authenticated Client
# ---------------------------------------------------------------------------


async def run_authenticated_calls() -> None:
    """Pass the Bearer header to every SDK operation."""
    security_key = os.environ["OS_SECURITY_KEY"]
    headers = {"Authorization": f"Bearer {security_key}"}
    client = AgentOSClient(base_url=BASE_URL)

    config = await client.aget_config(headers=headers)
    print(f"Authenticated with: {config.name or config.os_id}")

    response = await client.run_agent(
        agent_id=AGENT_ID,
        message="Reply with one sentence confirming this authenticated request.",
        headers=headers,
    )
    print(f"Authenticated run: {response.run_id}")
    print(response.content)


# ---------------------------------------------------------------------------
# Run the Example
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    asyncio.run(run_authenticated_calls())
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno fastapi
```

**2. Export environment variables**

```bash Mac/Linux theme={null}
export OS_SECURITY_KEY="your_os_security_key_here"
```

```bash Windows theme={null}
$Env:OS_SECURITY_KEY="your_os_security_key_here"
```

**3. Run the example**

Save the code above as `auth.py`, then run:

```bash theme={null}
python auth.py
```

Full source: [cookbook/05\_agent\_os/03\_python\_client/06\_auth.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/05_agent_os/03_python_client/06_auth.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.