Skip to main content

Basic Configuration

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

client = CorsaClient(
    base_url="https://api.corsa.finance",
    token=f"{os.environ['API_TOKEN']}:{os.environ['API_SECRET']}",
)

Configuration Options

OptionTypeDefaultDescription
base_urlstrBase URL for the Corsa API.
tokenstrAPI credentials for authentication, formatted as API_TOKEN:API_SECRET. Sent as Authorization: Bearer <token>. See Authentication.
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

import os
from corsa_sdk import CorsaClient

client = CorsaClient(
    base_url="https://api.corsa.finance",
    token=f"{os.environ['API_TOKEN']}:{os.environ['API_SECRET']}",
    timeout=60.0,
    headers={"X-Custom-Header": "value"},
)

Async Client

For async applications, use AsyncCorsaClient:
import os
from corsa_sdk import AsyncCorsaClient

async with AsyncCorsaClient(
    base_url="https://api.corsa.finance",
    token=f"{os.environ['API_TOKEN']}:{os.environ['API_SECRET']}",
) 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:
import os

# Sync
with CorsaClient(base_url="https://api.corsa.finance", token=f"{os.environ['API_TOKEN']}:{os.environ['API_SECRET']}") as client:
    # use client
    pass

# Async
async with AsyncCorsaClient(base_url="https://api.corsa.finance", token=f"{os.environ['API_TOKEN']}:{os.environ['API_SECRET']}") 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:
import os
from corsa_sdk import AuthenticatedClient
from corsa_sdk.api.alerts.create_alert import _get_kwargs

client = AuthenticatedClient(
    base_url="https://api.corsa.finance",
    token=f"{os.environ['API_TOKEN']}:{os.environ['API_SECRET']}",
)

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