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

# Authentication

> Authenticate Zerion API requests with an API key using HTTP Basic Auth, including header format, environments, and code samples in curl, JavaScript, and Python.

Zerion API supports three ways to authenticate a request:

| Method | Best for | How it works |
| - | - | - |
| **API key** | Apps and services with steady traffic | HTTP Basic Auth with a key from the [Dashboard](https://dashboard.zerion.io). Subject to rate limits. |
| **[x402](/build-with-ai/x402)** | AI agents and per-call workloads | Pay USDC on Base or Solana per request. No API key, no rate limits. |
| **[MPP](/build-with-ai/mpp)** | AI agents and per-call workloads | Pay USDC on Tempo per request. No API key, no rate limits. |

The rest of this page covers the API key flow. For pay-per-request flows, see the dedicated [x402](/build-with-ai/x402) and [MPP](/build-with-ai/mpp) pages.

## API key

Zerion API uses [HTTP Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#basic_authentication_scheme). You can get your API key from the [Dashboard](https://dashboard.zerion.io).

### Try it from the docs

Every API reference page has an interactive playground. Click **Try it**, paste your API key in the **Username** field, leave **Password** empty, and click **Send** to make a live request.

### Using the API from your code

When calling the API from code, append a colon to your API key (`your_api_key:`), Base64-encode it, and pass it in the `Authorization` header:

```
Authorization: Basic BASE64_ENCODED_KEY
```

<Tip>
  Go to the [Dashboard](https://dashboard.zerion.io) Get Started section for ready-to-use code snippets with your API key pre-filled.
</Tip>

<CodeGroup>
  ```bash cURL theme={null}
  # Transform your API key for Basic Auth
  API_KEY_TRANSFORMED=$(echo -n "YOUR_API_KEY:" | base64)

  # Make the request
  curl -X GET "https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/portfolio" \
    -H "Authorization: Basic $API_KEY_TRANSFORMED" \
    -H "accept: application/json"
  ```

  ```javascript JavaScript theme={null}
  // Transform your API key for Basic Auth
  const apiKey = 'YOUR_API_KEY';
  const apiKeyTransformed = btoa(apiKey + ':');

  // Make the request
  const response = await fetch(
    'https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/portfolio',
    {
      headers: {
        'Authorization': `Basic ${apiKeyTransformed}`,
        'accept': 'application/json'
      }
    }
  );
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests
  import base64

  # Transform your API key for Basic Auth
  api_key = 'YOUR_API_KEY'
  api_key_transformed = base64.b64encode(f'{api_key}:'.encode()).decode()

  # Make the request
  response = requests.get(
      'https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/portfolio',
      headers={
          'Authorization': f'Basic {api_key_transformed}',
          'accept': 'application/json'
      }
  )
  data = response.json()
  print(data)
  ```

  ```go Go theme={null}
  import (
      "encoding/base64"
      "net/http"
  )

  // Transform your API key for Basic Auth
  apiKey := "YOUR_API_KEY"
  apiKeyTransformed := base64.StdEncoding.EncodeToString([]byte(apiKey + ":"))

  // Make the request
  client := &http.Client{}
  req, _ := http.NewRequest("GET", "https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/portfolio", nil)
  req.Header.Set("Authorization", "Basic " + apiKeyTransformed)
  req.Header.Set("accept", "application/json")

  resp, _ := client.Do(req)
  defer resp.Body.Close()
  ```
</CodeGroup>

### Security best practices

<Warning>
  Never expose your API key in client-side code or public repositories.
</Warning>

* Store your API key in environment variables
* Make API requests from server-side code
* Rotate your key immediately if it's ever compromised
* Use separate keys for development and production

## Pay-per-request: x402 and MPP

Both x402 and MPP let you call Zerion API by paying a small USDC fee per request instead of presenting an API key. They're a better fit than API keys when:

* You're building an AI agent or automated pipeline that shouldn't manage long-lived credentials
* Traffic is bursty or unpredictable and you don't want to size a rate-limited plan
* You want usage-based cost accounting at the request level

The two protocols differ only in which chain they settle on:

* **[x402](/build-with-ai/x402)** ([Coinbase's open protocol](https://github.com/coinbase/x402)) - settles in USDC on **Base** or **Solana**. Uses the `PAYMENT-SIGNATURE` request header.
* **[MPP](/build-with-ai/mpp)** ([Machine Payments Protocol](https://mpp.dev)) - settles in USDC on **Tempo**. Uses the `Authorization: Payment` request header.

Both cover the same set of endpoints as API key authentication and accept the same parameters. Pick whichever chain your wallet already holds USDC on. The [Zerion CLI](/build-with-ai/zerion-cli) supports both via `--x402` / `--mpp` flags.


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