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

# Model gateway

> Call models from every major AI provider with a single key and prepaid credits

## Introduction

Laravel Cloud's model gateway gives your applications access to models from Anthropic, OpenAI, Google, Mistral, xAI, and many other providers through one API key. You don't need an account with each provider or a separate bill for each one. Instead, you add credits to your organization once, and every request your applications make through the gateway draws from that balance.

The gateway speaks the OpenAI Chat Completions and Anthropic Messages formats, so it works with the [Laravel AI SDK](https://laravel.com/docs/ai-sdk) and with any client that already talks to those APIs.

> [!NOTE]
>
> The model gateway is in early access. [**Request access**](https://cloud.laravel.com/early-access/model-gateway) and we'll enable the gateway for your organization as soon as it is ready.

## Getting started

Using the gateway takes three steps: add credits, attach a gateway key to your environment, and deploy.

**1. Add credits**

From your organization, open **Resources > Model gateway**, then click the **Credits** button. Enter an amount, accept the model gateway terms, and click **Pay**. See [adding credits](#adding-credits) to learn more.

**2. Attach a key to your environment**

Open the environment's canvas, click **Add resource**, then choose **Model gateway**. Select an existing key or click **Create new gateway key**, review the variable Laravel Cloud will inject, then click **Confirm and attach key**.

**3. Deploy the environment**

Deploy the environment for your application to receive the `LARAVEL_CLOUD_MODEL_GATEWAY_API_KEY` variable.

## Models

To browse the available models, open **Resources > Model gateway > Models**. You may search the list and filter it by provider or by API format. Each model's page lists its model ID, context window, maximum output, pricing, and links to the provider's documentation and terms.

You reference a model by its ID. Most IDs include the provider, such as `openai/gpt-5-5` or `mistral/mistral-large-3`. Anthropic models omit the provider, so you reference them as `claude-sonnet-5`.

### API formats

Every model uses exactly one API format, shown on the model's page. Use the endpoint that matches the model you are calling:

| Format | Base URL | Authentication header |
| - | - | - |
| OpenAI Chat Completions | `https://gateway.laravel.cloud/v1/openai/v1` | `Authorization: Bearer <key>` |
| Anthropic Messages | `https://gateway.laravel.cloud/v1/anthropic` | `x-api-key: <key>` |

The **REST API** section of the model gateway's **Overview** page shows the full URL for each format, along with ready-to-copy examples for the Laravel AI SDK and cURL.

## Gateway keys

Gateway keys authenticate your requests. Keys belong to your organization, and you may attach one key to as many environments as you like, though each environment may only have one key attached at a time. Every gateway key begins with `lcai_`.

### Creating keys

The simplest way to create a key is from the environment canvas while [attaching the gateway](#attaching-a-key-to-an-environment). Laravel Cloud names the key after the application and environment, then injects it into the environment for you, so you never need to copy it.

To create a key for use outside Laravel Cloud, such as on your local machine or another server, open **Resources > Model gateway**, then click **Create key** in the **Gateway keys** section. Enter a name and choose an [access level](#access-levels), then click **Create key**. Laravel Cloud displays the key once. Copy it and store it somewhere safe, since you won't be able to view it again.

Key names must be unique among your organization's active keys.

### Access levels

Each key has one of two access levels:

| Access level | Description |
| - | - |
| External | The gateway accepts requests using this key from anywhere, including your local machine and servers outside Laravel Cloud |
| Internal | The gateway only accepts requests using this key from Laravel Cloud |

Keys are external by default. If a key will only ever be used by your Cloud environments, make it internal, so a leaked key is useless anywhere else. You may change a key's access level at any time, and the change takes effect immediately.

### Editing and revoking keys

To rename a key or change its access level, open the key's **...** menu and select **Edit**. The key's panel also shows its ID, the last four characters of the key, and when it was last used.

To revoke a key, open the key's **...** menu and select **Revoke**, then type the key's name to confirm. Revoking a key immediately stops every request that uses it and detaches it from all of its environments. You can't undo this. Revoked keys remain in the list for 14 days, and you may reuse a revoked key's name for a new key.

> [!WARNING]
>
> Revoking a key that is attached to an environment breaks that environment's AI requests right away. Attach a new key and deploy the environment before revoking the old one.

## Attaching a key to an environment

Attaching a key requires the **Edit environments** permission.

**1. Add the resource**

Open the environment's canvas, click **Add resource**, then choose **Model gateway**.

**2. Select or create a key**

Select one of your organization's keys, or click **Create new gateway key** to create one for this environment.

**3. Review and confirm**

Review the variable Laravel Cloud will inject, then click **Confirm and attach key**.

**4. Deploy the environment**

Deploy the environment for your application to receive the key.

After you attach a key, the canvas displays a **Model gateway** card with the key's name and your organization's remaining credits. To view metrics or detach the key, open the card's **...** menu.

Attaching a key to an environment that already has one replaces the existing key. Detaching a key stops Laravel Cloud from injecting it, but leaves the key itself active for any other environments that use it. Both changes take effect on your next deployment.

### Injected environment variables

Attaching a key injects the following variable into the environment:

```ini theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
LARAVEL_CLOUD_MODEL_GATEWAY_API_KEY=lcai_xxxxxxxxxxxx
```

Laravel Cloud encrypts the key and masks it in your environment's variables. If you already defined a custom `LARAVEL_CLOUD_MODEL_GATEWAY_API_KEY` variable, Laravel Cloud removes it when you attach the key so the injected value can take effect.

## Configuring your application

> [tab] Laravel AI SDK
>
> Add a `laravel-cloud` provider to your application's `config/ai.php` configuration file. For models that use the OpenAI Chat Completions format, use the `openai-compatible` driver:
>
> ```php theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
> 'providers' => [
>     'laravel-cloud' => [
>         'driver' => 'openai-compatible',
>         'url' => 'https://gateway.laravel.cloud/v1/openai/v1',
>         'key' => env('LARAVEL_CLOUD_MODEL_GATEWAY_API_KEY'),
>     ],
> ],
> ```
>
> For models that use the Anthropic Messages format, use the `anthropic` driver and the Anthropic base URL:
>
> ```php theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
> 'providers' => [
>     'laravel-cloud' => [
>         'driver' => 'anthropic',
>         'url' => 'https://gateway.laravel.cloud/v1/anthropic/v1',
>         'key' => env('LARAVEL_CLOUD_MODEL_GATEWAY_API_KEY'),
>     ],
> ],
> ```
>
> Then, specify the provider and model when prompting an agent:
>
> ```php theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
> agent()->prompt('Hello', provider: 'laravel-cloud', model: 'openai/gpt-5-5');
> ```

> [tab] cURL
>
> For models that use the OpenAI Chat Completions format:
>
> ```sh theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
> curl https://gateway.laravel.cloud/v1/openai/v1/chat/completions \
>   -H "Authorization: Bearer $LARAVEL_CLOUD_MODEL_GATEWAY_API_KEY" \
>   -H "content-type: application/json" \
>   -d '{"model":"openai/gpt-5-5","messages":[{"role":"user","content":"Hello"}]}'
> ```
>
> For models that use the Anthropic Messages format:
>
> ```sh theme={"theme":{"light":"min-light","dark":"material-theme-palenight"}}
> curl https://gateway.laravel.cloud/v1/anthropic/v1/messages \
>   -H "x-api-key: $LARAVEL_CLOUD_MODEL_GATEWAY_API_KEY" \
>   -H "anthropic-version: 2023-06-01" \
>   -H "content-type: application/json" \
>   -d '{"model":"claude-sonnet-5","max_tokens":1024,"messages":[{"role":"user","content":"Hello"}]}'
> ```

> [tab] Other clients
>
> Any OpenAI or Anthropic SDK can call the gateway. Point the SDK's base URL at the gateway URL for the model's [API format](#api-formats), and pass your gateway key as the API key.

## Credits

The model gateway is prepaid. Your organization keeps a single credit balance, and Laravel Cloud deducts the cost of each request from it based on the tokens the request used. Gateway usage is billed separately from your plan, so your plan's included usage does not cover it.

Your remaining balance appears on the **Credits** button of the model gateway's **Overview** page and on the **Model gateway** card of every environment with an attached key. Both show a **Running low** warning when your balance drops below \$5.

### Adding credits

To add credits, click the **Credits** button on the model gateway's **Overview** page, enter an amount between $10 and $10,000, then click **Pay**. The first time you add credits, you must accept the [model gateway terms](https://laravel.com/cloud/legal/terms#model-gateway).

To prevent abuse, new organizations may add up to \$50 in credits per billing period and can't enable automatic top-up. These limits lift as your organization builds a payment history with Laravel Cloud.

### Automatic top-up

To keep your applications from running out of credits, you may have Laravel Cloud add credits automatically. Open the **Automatic top-up** tab of the credits dialog, then enter a top-up amount and a threshold. Whenever your balance falls below the threshold, Laravel Cloud charges your card for the top-up amount. Both values must be at least \$10, and you must have a balance before you enable automatic top-up.

If an automatic top-up fails, Laravel Cloud notifies you through your organization's [payment notifications](https://cloud.laravel.com/docs/notifications.md), and gateway requests stop once your balance runs out.

### Running out of credits

When your balance reaches zero, the gateway rejects requests from every key in your organization. Your applications should handle these failures gracefully. As soon as you add credits, the gateway accepts requests again without any further action.

## Logs and metrics

The model gateway's **Overview** page charts your organization's requests, tokens, and costs over the last hour, day, 7 days, or 30 days.

The **Logs** page lists each request your applications make through the gateway, with its model, token usage, duration, cost, and HTTP status. Click a request to view its full details, including cache usage, the endpoint, and the key that made it. Requests appear about a minute after they finish.

Laravel Cloud records metadata about each request, but it never stores your prompts or the model's responses.

> [!TIP]
>
> The gateway's logs show what each request cost. [Laravel Nightwatch](https://nightwatch.laravel.com) shows where it came from, tracing each outgoing request to the gateway back to the route, job, or command that made it.

## Permissions

The model gateway has its own permissions:

| Permission | Allows |
| - | - |
| View Model gateway keys | Viewing keys, as well as the gateway's overview, logs, models, and credits |
| Create Model gateway keys | Creating keys |
| Edit Model gateway keys | Renaming keys and changing their access level |
| Revoke Model gateway keys | Revoking keys |

The Admin, Manager, and Developer roles include all four permissions, while the Viewer role can only view. With [custom roles](https://cloud.laravel.com/docs/rbac.md#custom-roles), you may grant them separately. Attaching a key to an environment requires the **Edit environments** permission, and adding credits requires the **Edit organization billing** permission.
