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

# Authentication

> Secure your API requests with API keys

## Overview

All protected Daya API requests require authentication using API keys. Each key is tied to a specific merchant and environment (Sandbox or Production).

> [!WARNING]
>
> API keys authorize access to your account within their granted permissions. **Never** share them publicly or commit them to version control.

## API Keys

### Generating Keys

1. Sign up at [dashboard.daya.co](https://dashboard.daya.co)
2. Navigate to **API Keys**
3. Generate separate keys for Sandbox and Production

### Key Format

| Environment | Prefix | Example |
| - | - | - |
| Sandbox | `sk_sandbox_` | `sk_sandbox_abc123...` |
| Production | `sk_live_` | `sk_live_xyz789...` |

### Environments

| Environment | Purpose | Base URL |
| - | - | - |
| **Sandbox** | Testing with fake funds | `https://api.sandbox.daya.co` |
| **Production** | Live transactions with real money | `https://api.daya.co` |

> [!NOTE]
>
> Sandbox and Production environments are **completely isolated**. Data and keys do not cross environments.

## Making Authenticated Requests

Include your API key in the `X-Api-Key` header on every protected request:

```bash cURL theme={"dark"}
curl --request GET \
  --url https://api.daya.co/v1/rates \
  --header 'X-Api-Key: YOUR_API_KEY'
```

```javascript JavaScript theme={"dark"}
const response = await fetch('https://api.daya.co/v1/rates', {
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
});
```

```python Python theme={"dark"}
import requests

headers = {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
}
response = requests.get('https://api.daya.co/v1/rates', headers=headers)
```

```go Go theme={"dark"}
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.daya.co/v1/rates", nil)
req.Header.Add("X-Api-Key", "YOUR_API_KEY")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
```

## Funding and bridge permissions

For scoped Business API keys, funding-account creation requires `write`. Bridge creation requires `withdraw`; `write` alone is insufficient. Reads require `read`. The merchant and account must remain active and the key must belong to the correct environment.

Bridge sandbox simulations require both `write` and `withdraw`. See [sandbox requests](https://docs.daya.co/api-reference/sandbox/create-sandbox-deposit.md#bridge-simulations).

## Idempotent Write Requests

Endpoints that create resources, such as `POST /v1/funding-accounts`, `POST /v1/transfers`, `POST /v1/merchant/withdrawals`, and `POST /v1/bridges`, also require an `X-Idempotency-Key` header. Use a new value for each new write attempt, and reuse the same value only when retrying the exact same request.

```bash cURL theme={"dark"}
curl --request POST \
  --url https://api.daya.co/v1/funding-accounts \
  --header 'X-Api-Key: YOUR_API_KEY' \
  --header 'X-Idempotency-Key: funding-account-20260320-0001' \
  --header 'Content-Type: application/json'
```

For temporary crypto funding and bridge creates, successful retries return the original address and deadline. A retry does not renew an expired request; use GET for current status. Keys are retained for 24 hours by default. A retry after that period can create another resource. See [sandbox retry behavior](https://docs.daya.co/api-reference/sandbox/create-sandbox-deposit.md#bridge-simulations).

## Environment Isolation

> [tab] Sandbox
>
> **For:** Integration testing, development
>
> **Characteristics:**
>
> * Separate API keys from production
> * Simulated NGN deposits
> * Testnet USDC/USDT (no real value)
> * Same API surface as production
> * No KYB required
>
> **Use when:** Building and testing your integration

> [tab] Production
>
> **For:** Live transactions with real money
>
> **Characteristics:**
>
> * Unique production API keys
> * Real NGN bank transfers
> * Mainnet USDC/USDT (real value)
> * KYB verification required
> * Audit logs and compliance monitoring
>
> **Use when:** Serving real users and processing actual funds

> [!WARNING]
>
> **Never** use production keys in sandbox or vice versa. The API will reject cross-environment requests.

## Security Best Practices

> [accordion] Store keys securely
>
> * Use environment variables or secret management systems (AWS Secrets Manager, HashiCorp Vault)
> * Never hardcode keys in source code
> * Never commit keys to Git repositories
>
> ```bash .env theme={"dark"}
> DAYA_SANDBOX_KEY=sk_sandbox_abc123...
> DAYA_PRODUCTION_KEY=sk_live_xyz789...
> ```

> [accordion] Rotate keys regularly
>
> Rotate API keys every 90 days or immediately if compromised:
>
> 1. Generate new key in dashboard
> 2. Update your application configuration
> 3. Verify new key works
> 4. Delete old key

> [accordion] Implement rate limiting
>
> Implement client-side rate limiting to avoid hitting API limits:
>
> * 100 requests per minute per key
> * Your merchant's funding account creation quota (see [Limits](https://docs.daya.co/limits/overview.md))

## Error Responses

### 401 Unauthorized

The API could not authenticate the request:

```json theme={"dark"}
{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "invalid api key",
    "request_id": "example-request-id"
  }
}
```

The same response covers missing, malformed, incorrect, expired or revoked credentials, and a merchant account that is missing or inactive. The response does not identify which condition applies.

Check the `X-API-Key` header, configured key and environment. If an existing key stops working, contact [support@daya.co](mailto:support@daya.co) with the request ID. Do not share your key or rotate it just to diagnose this response. A replacement key does not remove an account restriction.

### 403 Forbidden

An authenticated request can still lack the scope required for an operation:

```json theme={"dark"}
{
  "error": {
    "code": "FORBIDDEN",
    "message": "api key does not grant the required scope",
    "request_id": "example-request-id"
  }
}
```

Check the key's grants for the operation. Authentication can also reject a grant-related request with the generic 401 above; do not depend on a distinct error for every access restriction.

### 503 Service Unavailable

If credential verification is temporarily unavailable, write requests fail with:

```json theme={"dark"}
{
  "error": {
    "code": "INTEGRATION_FAILED",
    "message": "api key verification unavailable",
    "request_id": "example-request-id"
  }
}
```

Read requests may remain available during this outage. Retry with backoff and preserve the operation's original idempotency key where supported. Do not create a new transfer or withdrawal to work around a verification failure.

## Webhook Authentication

Webhooks use **HMAC-SHA256** signatures, not API keys. See [Webhook Verification](https://docs.daya.co/api-reference/webhooks/verification.md).

## Testing Authentication

Verify your API key works:

```bash cURL theme={"dark"}
curl --request GET \
  --url https://api.sandbox.daya.co/v1/rates?from=NGN \
  --header 'X-Api-Key: YOUR_SANDBOX_KEY'
```

```javascript JavaScript theme={"dark"}
// Test authentication
async function testAuth() {
  const response = await fetch(
    'https://api.sandbox.daya.co/v1/rates?from=NGN',
    {
      headers: { 'X-Api-Key': 'YOUR_SANDBOX_KEY' }
    }
  );

  if (response.ok) {
    console.log('Authentication successful');
  } else {
    console.error('Authentication failed:', response.status);
  }
}
```

Expected response (if successful):

```json theme={"dark"}
{
  "rate_id": "rate_abc123",
  "from": "NGN",
  "to": "USDC",
  "rate": 1545.50,
  ...
}
```

## Next Steps

> [card] [Core Concepts](https://docs.daya.co/concepts/overview.md)
>
> Understand funding accounts, deposits, transfers, and rates

> [card] [Quick Start](https://docs.daya.co/quickstart.md)
>
> Create your first funding account


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.