Apikeys API (Python)

Methods, examples, and parameters for client.apikeys.

Module Overview

Create, rotate, and revoke API keys for tenants and automation workflows.

Available Methods

  • client.apikeys.list() - List active and revoked keys.
  • client.apikeys.create() - Create a new API key.
  • client.apikeys.revoke() - Revoke a key immediately.

Examples

Python
from therouter import TheRouter.ai

client = TheRouter.ai(
    api_key=os.getenv("THEROUTER_API_KEY"),
    base_url="https://api.therouter.ai/v1",
)

key = client.apikeys.create(
    name="ci-pipeline",
    scope=["responses:write", "models:read"],
)

print(key.prefix)
apikeys-response.json
{
  "id": "req_01HXYZ123",
  "module": "apikeys",
  "status": "ok"
}

Parameter Types

NameTypeRequiredDescription
name
stringRequiredHuman-friendly key label.
scope
string[]Allowed capabilities for this key.
expires_at
string (ISO datetime)Optional expiration timestamp.
SDK parity
Method signatures are aligned across SDKs so migration between TypeScript and Python stays predictable.