Oauth API (Python)
Methods, examples, and parameters for client.oauth.
Module Overview
Create OAuth clients and exchange authorization codes for scoped access tokens.
Available Methods
client.oauth.clients.create()- Create OAuth client credentials.client.oauth.authorizeUrl()- Generate user authorization URL.client.oauth.tokens.exchange()- Exchange code for access token.
Examples
Python
from therouter import TheRouter.ai
client = TheRouter.ai(
api_key=os.getenv("THEROUTER_API_KEY"),
base_url="https://api.therouter.ai/v1",
)
url = client.oauth.authorize_url(
client_id=os.getenv("THEROUTER_CLIENT_ID"),
redirect_uri="https://app.example.com/oauth/callback",
scope="responses:write models:read",
)
print(url)oauth-response.json
{
"id": "req_01HXYZ123",
"module": "oauth",
"status": "ok"
}Parameter Types
| Name | Type | Required | Description |
|---|---|---|---|
client_id | string | Required | OAuth client identifier. |
redirect_uri | string | Required | Allowed redirect URI. |
scope | string | Space-delimited requested scopes. |
SDK parity
Method signatures are aligned across SDKs so migration between TypeScript and Python stays predictable.