Skip to main content

Basic Configuration

Import CorsaClient and configure it with your API URL and token:
from corsa_sdk import CorsaClient

client = CorsaClient(
    base_url="https://api.corsa.finance",
    token="your-api-token",
)

Configuration Options

OptionTypeDefaultDescription
base_urlstrBase URL for the Corsa API.
tokenstrAPI token for authentication. Sent as Authorization: Bearer <token>.
timeoutfloatNoneRequest timeout in seconds.
headersdict[str, str]{}Additional HTTP headers to include on every request.
raise_on_unexpected_statusboolTrueRaise UnexpectedStatus for undocumented HTTP status codes.
httpx_argsdict[str, Any]{}Extra keyword arguments passed to the underlying httpx client.

Custom Headers and Timeout

client = CorsaClient(
    base_url="https://api.corsa.finance",
    token="your-api-token",
    timeout=60.0,
    headers={"X-Custom-Header": "value"},
)

Async Client

For async applications, use AsyncCorsaClient:
from corsa_sdk import AsyncCorsaClient

async with AsyncCorsaClient(
    base_url="https://api.corsa.finance",
    token="your-api-token",
) as client:
    httpx_client = client.raw_client.get_async_httpx_client()
    response = await httpx_client.request(**kwargs)

Context Managers

Both clients support context managers for automatic cleanup:
# Sync
with CorsaClient(base_url="https://api.corsa.finance", token="your-api-token") as client:
    # use client
    pass

# Async
async with AsyncCorsaClient(base_url="https://api.corsa.finance", token="your-api-token") as client:
    # use client
    pass

Direct Module Access

For full control over the HTTP response (status code, headers, raw body), use the generated API modules directly with the underlying AuthenticatedClient:
from corsa_sdk import AuthenticatedClient
from corsa_sdk.api.alerts.create_alert import _get_kwargs

client = AuthenticatedClient(
    base_url="https://api.corsa.finance",
    token="your-api-token",
)

httpx_client = client.get_httpx_client()
response = httpx_client.request(**_get_kwargs(body=...))
print(response.status_code, response.json())