Installation

Install the Authed SDK using pip:

pip install authed

Basic setup

The easiest way to get started is to use our authed init setup command, which will:

  • Generate a secure key pair for your agent
  • Create a new agent under your provider
  • Set up your environment variables automatically
authed init setup --provider-id "your-provider-id" --provider-secret "your-provider-secret"

Initialize the SDK

After running the setup command, you can initialize the SDK using environment variables:

from authed import Authed

# Initialize from environment variables (recommended)
auth = Authed.from_env()

If you need more control, you can also initialize explicitly:

# Initialize with explicit credentials
auth = Authed.initialize(
    registry_url="https://api.getauthed.dev",
    agent_id="your-agent-id",
    agent_secret="your-agent-secret",
    private_key="your-private-key",
    public_key="your-public-key"
)

Environment Variables

The SDK uses these environment variables (automatically configured by authed init setup):

VariableRequiredDescription
AUTHED_REGISTRY_URLYesRegistry URL
AUTHED_AGENT_IDFor outgoingAgent ID for requests
AUTHED_AGENT_SECRETFor outgoingAgent secret
AUTHED_PRIVATE_KEYFor outgoingPrivate key for signing
AUTHED_PUBLIC_KEYFor incomingPublic key for verification

Request authentication

Protecting incoming requests

from fastapi import FastAPI, Request
from agent_auth_client import verify_fastapi

app = FastAPI()

# Required authentication
@app.get("/protected")
@verify_fastapi()
async def protected_endpoint(request: Request):
    return {"message": "This endpoint requires authentication"}

Making authenticated requests

from agent_auth_client import protect_httpx, protect_requests
import httpx
import requests

# Using HTTPX (async)
@protect_httpx()
async def make_authenticated_request():
    async with httpx.AsyncClient() as client:
        # The decorator automatically adds auth headers
        response = await client.get(
            "https://api.example.com/some-endpoint",
            headers={"target-agent-id": "target-agent-uuid"}
        )
        return response.json()

# Using requests (sync)
@protect_requests()
def make_sync_request():
    with requests.Session() as session:
        # The decorator automatically adds auth headers
        response = session.get(
            "https://api.example.com/some-endpoint",
            headers={"target-agent-id": "target-agent-uuid"}
        )
        return response.json()

Combined example

@app.get("/chain-request")
@verify_fastapi()  # Verify incoming requests
@protect_httpx()   # Protect outgoing requests
async def chain_request(request: Request):
    async with httpx.AsyncClient() as client:
        response = await client.get(
            "https://api.example.com/another-service",
            headers={"target-agent-id": "target-agent-uuid"}
        )
        return {
            "incoming_auth": "valid",
            "outgoing_response": response.json()
        }

Troubleshooting

Security best practices