> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corsa.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK Configuration & Authentication Setup

> Configure the Corsa Python SDK with API credentials, custom headers, timeouts, and async support.

## Basic Configuration

Import `CorsaClient` and configure it with your API URL and token:

```python theme={null}
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

| Option                       | Type             | Default | Description                                                                                                                                                  |
| ---------------------------- | ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `base_url`                   | `str`            | —       | Base URL for the Corsa API.                                                                                                                                  |
| `token`                      | `str`            | —       | API credentials for authentication, formatted as `API_TOKEN:API_SECRET`. Sent as `Authorization: Bearer <token>`. See [Authentication](/api/authentication). |
| `timeout`                    | `float`          | `None`  | Request timeout in seconds.                                                                                                                                  |
| `headers`                    | `dict[str, str]` | `{}`    | Additional HTTP headers to include on every request.                                                                                                         |
| `raise_on_unexpected_status` | `bool`           | `True`  | Raise `UnexpectedStatus` for undocumented HTTP status codes.                                                                                                 |
| `httpx_args`                 | `dict[str, Any]` | `{}`    | Extra keyword arguments passed to the underlying httpx client.                                                                                               |

## Custom Headers and Timeout

```python theme={null}
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`:

```python theme={null}
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:

```python theme={null}
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`:

```python theme={null}
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())
```
