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

# Authentication

> Configure your Paubox API credentials for the Rust SDK.

## Obtain your credentials

The Email API client requires two credentials:

* **API key**: a secret token that authenticates your requests
* **Username**: your Paubox API endpoint username (not your login email)

Both are available in the [Paubox dashboard](https://next.paubox.com) under **API Credentials**.

## Option 1: Environment variables (recommended)

```bash theme={null}
export PAUBOX_API_KEY="YOUR_API_KEY"
export PAUBOX_API_USER="YOUR_USERNAME"
```

```rust theme={null}
let client = PauboxClient::from_env()?;
```

`from_env()` returns `Err(PauboxError::EnvVar(...))` immediately if either variable is missing or empty.

## Option 2: Direct constructor

```rust theme={null}
let client = PauboxClient::new("YOUR_API_KEY", "YOUR_USERNAME");
```

## Option 3: Builder (with custom timeout or base URL)

```rust theme={null}
use std::time::Duration;

let client = PauboxClient::builder()
    .api_key("YOUR_API_KEY")
    .api_user("YOUR_USERNAME")
    .timeout(Duration::from_secs(15))
    .build()?;
```

Use `.base_url(url)` in tests to point at a mock server.

The SDK sets the `Authorization` header automatically on every request:

```
Authorization: Token token=YOUR_API_KEY
```

## Forms client

`FormsClient` requires no credentials:

```rust theme={null}
let forms = FormsClient::new();
```

If you already have a `PauboxClient`, reuse its HTTP connection pool:

```rust theme={null}
let forms = email_client.forms();
```

## Security notes

* Never hard-code credentials in source files.
* The SDK does not log API keys or request bodies.
