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

# Integrating with the Gateway

> Connect your application to AI Stats Gateway, start on free models, then scale to paid models.

The AI Stats Gateway gives you a single, unified API surface for accessing multiple model providers. Follow this guide to create an API key, send your first request, and adopt the conventions that keep integrations production ready.

***

## Before you begin

Make sure you have the following in place:

* An AI Stats account with Gateway access.
* At least one API key generated from your [dashboard](https://ai-stats.phaseo.app/gateway/keys).
* An HTTP client such as `curl`, `fetch`, or `axios`.
* A model ID supported by the Gateway (for example `google/gemma-3-27b:free` for zero-deposit start).

***

## 1. Create and store an API key

1. Log in to the AI Stats dashboard.
2. Navigate to **Gateway -> API Keys**.
3. Create a new key, give it a descriptive name, and copy the generated value.
4. Store the key securely using your secret manager or environment variables:

```bash theme={null}
# .env
AI_STATS_API_KEY="aistats_v1_sk_<kid>_<secret>"
```

> Tip
> Rotate keys regularly and remove any that are no longer needed. This keeps access scoped and auditable.

***

## 2. Choose an endpoint and model

Pick the endpoint that matches your use case. The Gateway normalizes payloads across providers, so request shapes are consistent:

| Endpoint                 | When to use it                                     |
| ------------------------ | -------------------------------------------------- |
| `/v1/chat/completions`   | Conversational interfaces, agents, and assistants. |
| `/v1/responses`          | Multi-step reasoning and structured responses.     |
| `/v1/messages`           | Anthropic-compatible messages API.                 |
| `/v1/moderations`        | Safety and content policy checks.                  |
| `/v1/images/generations` | Image generation from text prompts.                |

Refer to the [API Reference](../api-reference/introduction.mdx) for the complete list of supported parameters and responses.

<Note>
  Free-model IDs end with `:free` and can be called without depositing credits. Paid-model calls require available wallet balance.
</Note>

***

## 3. Send a request

Here is a minimal `curl` example using the chat completions endpoint:

```bash theme={null}
curl https://api.phaseo.app/v1/chat/completions \
    -H "Authorization: Bearer $AI_STATS_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
        "model": "google/gemma-3-27b:free",
        "messages": [
            { "role": "system", "content": "You are a helpful assistant." },
            { "role": "user", "content": "Explain the benefits of AI." }
        ]
    }'
```

***

## 4. Configure environments

Store your API key in environment variables for different environments:

```bash theme={null}
# .env.local
AI_STATS_API_KEY="aistats_v1_sk_<kid>_<secret>"
AI_STATS_BASE_URL="https://api.phaseo.app/v1"
```

When making requests, always include the `Authorization` header with your API key:

```http theme={null}
Authorization: Bearer $AI_STATS_API_KEY
```

***

## 5. Next steps

* Review [Authentication](./authentication.mdx) to learn about header formats and workspace tokens.
* Learn how [Routing and fallbacks](../guides/routing-and-fallbacks.mdx) work in production.
* Browse [Examples](../guides/examples.mdx) to see complete integrations in popular frameworks.
* Explore the [SDK Reference](../sdk-reference/typescript/overview.mdx) for language-specific usage.
