Authenticate a RemoteAgent run with a Bearer credential

Restart the native AgentOS backend with OS_SECURITY_KEY set, then pass that same value through RemoteAgent.arun(auth_token=...).

Restart the native AgentOS backend with OS_SECURITY_KEY set, then pass that same value through RemoteAgent.arun(auth_token=...). The token is attached to this call rather than stored on the RemoteAgent.

remote_auth.py
"""
Authenticate a RemoteAgent run with a Bearer credential
=======================================================

Restart the native AgentOS backend with OS_SECURITY_KEY set, then pass that
same value through RemoteAgent.arun(auth_token=...). The token is attached to
this call rather than stored on the RemoteAgent.

Prerequisites: start `servers/agentos_server.py` with OS_SECURITY_KEY and set OPENAI_API_KEY
Run: .venvs/demo/bin/python cookbook/05_agent_os/20_remote/06_remote_auth.py
Try: run this client with a wrong OS_SECURITY_KEY and observe HTTP 401
"""

import asyncio
import os

from agno.agent import RemoteAgent

# ---------------------------------------------------------------------------
# Create Remote Agent
# ---------------------------------------------------------------------------

remote_assistant = RemoteAgent(
    base_url="http://127.0.0.1:7780",
    agent_id="assistant-agent",
)

# ---------------------------------------------------------------------------
# Run Authenticated Remote Agent
# ---------------------------------------------------------------------------

async def run_authenticated_agent() -> None:
    """Pass the configured security key as this run's Bearer token."""
    security_key = os.environ["OS_SECURITY_KEY"]
    response = await remote_assistant.arun(
        "Confirm this authenticated remote request in one sentence.",
        auth_token=security_key,
    )
    print(f"Authenticated run: {response.run_id}")
    print(response.content)

if __name__ == "__main__":
    asyncio.run(run_authenticated_agent())

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno

Export environment variables

export OS_SECURITY_KEY="your_os_security_key_here"

Start the protected upstream

In another terminal, follow Native AgentOS server to install its dependencies and set its OpenAI key. Stop any existing server on port 7780. After its normal environment setup, set OS_SECURITY_KEY to the same value you set above, then run python agentos_server.py from the directory where you saved that file. Keep it running while this client executes.

The provider key is required by the server; this client only needs the shared Bearer credential. When you finish, restart the backend with OS_SECURITY_KEY unset before trying the ordinary remote examples or gateway.

Run the example

Save the code above as remote_auth.py, then run:

python remote_auth.py

Full source: cookbook/05_agent_os/20_remote/06_remote_auth.py