An *LLM API proxy* is an Apigee API proxy that fronts a large
language model (LLM). You can create one from the LLM template in the proxy
creation wizard, or by declaring the proxy's operation mode directly in the proxy
bundle (see [The ProxyOperationMode element](https://docs.cloud.google.com/apigee/docs/api-platform/develop/llm-proxies-overview.md.txt#proxyoperationmode)).
The template lets you stand up a proxy in front of an LLM without hand-authoring
the provider's endpoint URL or auth policies.

LLM proxies let you apply Apigee's API management capabilities
to LLM traffic by using the same proxy model as the rest of your APIs.
You can manage capabilities such as security, quota, analytics, and
[AI gateway
policies](https://docs.cloud.google.com/apigee/docs/api-platform/get-started/ai-capabilities). When a proxy is declared as an LLM proxy, Apigee returns
the responses that it generates---such as policy faults, upstream errors, and
custom messages---in the LLM provider's own format. Because these responses are
indistinguishable from the model's, agents, SDKs, and frameworks (such as the
OpenAI, Agent Platform, and Anthropic SDKs) need
no gateway-specific code: Apigee stays transparent in the agent-to-model
interaction. For more information, see
[LLM response formatting](https://docs.cloud.google.com/apigee/docs/api-platform/develop/llm-proxies-overview.md.txt#llm-response-formatting).

## Supported model providers

The LLM template supports the following providers:

| Provider | Access | Description |
|---|---|---|
| **Gemini** | Google models through Agent Platform | The proxy targets the model through Agent Platform and forwards requests in the OpenAI-compatible chat completions format. |
| **Anthropic** | Partner models through Agent Platform | The proxy targets the model's native Agent Platform endpoint. Apigee adds the request fields that Agent Platform requires so that minimal requests succeed. |
| **OpenAI** | OpenAI directly | The proxy targets OpenAI's Chat Completions endpoint and authenticates with your OpenAI API key. |

> [!NOTE]
> **Note:** Only text models appear in the model picker in the LLM template step. Non-text models (for example, image or video generation, embeddings, and speech models) are filtered out.

## How LLM proxies work

When you select a model in the LLM template, the wizard completes the
following steps:

- Sets the proxy's **target URL** to the selected model's provider endpoint. You can edit the target later if you need a different endpoint, such as a streaming endpoint.
- Generates the **outbound authentication** policies for the provider, which is either a Google access token for Agent Platform providers or an API-key lookup for OpenAI.
- Declares the proxy's operation mode by adding `<ProxyOperationMode>LLM</ProxyOperationMode>` to the proxy bundle, which activates [LLM response
  formatting](https://docs.cloud.google.com/apigee/docs/api-platform/develop/llm-proxies-overview#llm-response-formatting).

Complete the remaining wizard steps (proxy details and deployment) to create
the proxy.

## Model availability

The model picker shows only models that your Google Cloud project can call. If a
model you expect is missing, it might not be enabled for your project. Use the
**Enable additional models in Agent Platform** link in the model picker to
open Model Garden, enable the model, and then reopen the wizard.

## Authentication

Outbound authentication depends on the provider:

- **Gemini and Anthropic (Agent Platform):** The Apigee runtime calls Agent Platform with a Google access token minted from the proxy's **deployment
  service account** . Grant that service account the **Agent Platform User** (`roles/aiplatform.user`) role, and grant the deploying user the **Service Account User** (`roles/iam.serviceAccountUser`) role on it. For more information, see [Using
  Google authentication](https://docs.cloud.google.com/apigee/docs/api-platform/security/google-auth/overview).
- **OpenAI:** The proxy reads your OpenAI API key from an encrypted [key value map
  (KVM)](https://docs.cloud.google.com/apigee/docs/api-platform/cache/key-value-maps). In the wizard, either provide an API key (which Apigee stores in a new encrypted KVM at deploy time) or point to an existing encrypted KVM that holds the key in an `api-key` entry.

## Regions

For Gemini and Anthropic, the proxy targets the Agent Platform `global`
endpoint. If you need a specific regional endpoint, edit the proxy's target URL
after you create the proxy.

## The ProxyOperationMode element

An LLM proxy is identified by a `<ProxyOperationMode>` element
on the `<APIProxy>` root element of the proxy bundle. This
element declares the architectural style of the API that the proxy fronts so
that Apigee and downstream tools can treat the proxy's type as a
validated fact instead of inferring it. When you create a proxy from the LLM
template, Apigee adds
`<ProxyOperationMode>LLM</ProxyOperationMode>` for you. You
can also declare it yourself when authoring a bundle by hand (see
[Create an LLM
API proxy](https://docs.cloud.google.com/apigee/docs/api-platform/develop/create-llm-proxy#create)).

```xml
<APIProxy name="my-llm-api">
  <ProxyOperationMode>LLM</ProxyOperationMode>
  <Description>My LLM proxy.</Description>
</APIProxy>
```

Key characteristics of `<ProxyOperationMode>`:

- **Validated at create and import time.** Apigee validates the value when you create or import the bundle---not at deploy time. An unsupported value rejects the API call, and no revision is created.
- **Per revision.** Each revision of a proxy carries its own `<ProxyOperationMode>` value, and the value can change from one revision to the next. The Apigee runtime uses the deployed revision's value, so a rollback restores the previous revision's behavior.
- **Preserved on export.** When you export the bundle, the value you declared is preserved. If you omit the element, no element is added on export, and the proxy behaves as a standard REST proxy.

The element accepts the following values:

| Value | Behavior |
|---|---|
| `LLM` | The proxy fronts an LLM API. Apigee activates [LLM response formatting](https://docs.cloud.google.com/apigee/docs/api-platform/develop/llm-proxies-overview.md.txt#llm-response-formatting) and resolves the provider from the target URL. |
| `MCP` | The proxy fronts a Model Context Protocol (MCP) tool server. Apigee formats responses as JSON-RPC 2.0 envelopes. MCP proxies are documented separately. |

The element has no default value. If you omit it, the proxy is not marked as an
LLM or MCP proxy. The proxy behaves as a standard REST proxy and LLM response
formatting is not applied.

## LLM response formatting

On a proxy declared with
`<ProxyOperationMode>LLM</ProxyOperationMode>`,
Apigee formats the responses that it generates into the LLM
provider's native format. This includes policy faults (such as a quota or
security block), an upstream error, an explicit
[RaiseFault](https://docs.cloud.google.com/apigee/docs/api-platform/reference/policies/raise-fault-policy.md.txt),
and custom messages that you author with the
[AssignMessage](https://docs.cloud.google.com/apigee/docs/api-platform/reference/policies/assign-message-policy.md.txt)
policy. Successful responses from the model pass through unchanged.

This keeps Apigee transparent in the interaction between an agent and
its model:

- **Transparent to the agent.** The responses that the gateway generates look like the model's own, so the agent doesn't need to know that a gateway is in the path.
- **No client changes.** Existing agents, SDKs, and frameworks parse these responses on the same code path they already use for the model.
- **Resilient agents.** An error carries the accurate HTTP status code and the provider's native error type, so it flows through the agent's existing retry and error-handling logic instead of breaking its parser.
- **Govern without redesign.** You can enforce quota, security, and safety controls on agent-to-LLM traffic without reworking the client.

For example, when a
[Quota](https://docs.cloud.google.com/apigee/docs/api-platform/reference/policies/quota-policy.md.txt) policy
blocks a request, Apigee returns an HTTP `429`. Without LLM
response formatting, the gateway returns its standard error body, which does not
match the envelope that the model's SDK expects---so an agent built on that SDK
can fail when it tries to parse the response:

```json
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
{
  "fault": {
    "faultstring": "Rate limit quota violation. Quota limit exceeded.",
    "detail": {"errorcode": "policies.ratelimit.QuotaViolation"}
  }
}
```

With LLM response formatting, the gateway returns the same condition in the
provider's native envelope (here, OpenAI), preserving the accurate HTTP status code.
The agent parses it like any other response from the model:

```json
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
{
  "error": {
    "message": "Rate limit quota violation. Quota limit exceeded.",
    "type": "rate_limit_error",
    "param": null,
    "code": null
  }
}
```

### How the response is formatted

Apigee formats a gateway-generated response in one of two ways:

- **Custom message.** An [AssignMessage](https://docs.cloud.google.com/apigee/docs/api-platform/reference/policies/assign-message-policy.md.txt) policy that carries an `<LLMResponse>` element runs on the response. You supply plain message text, and Apigee wraps it in the provider's native envelope. The HTTP status is `200` by default, or the value you set in `<LLMResponse><StatusCode>`. A status below `400` produces the provider's success envelope; a status of `400` or higher produces the provider's error envelope.
- **Default fault.** A policy raises a fault (for example, a quota violation or a security block) and no AssignMessage with `<LLMResponse>` runs on the response path. Apigee constructs the provider's error envelope carrying the fault message and preserves the fault's HTTP status code.

For details and examples of authoring custom messages, see
[Format
Apigee responses for an LLM proxy](https://docs.cloud.google.com/apigee/docs/api-platform/develop/create-llm-proxy#format-responses).

### Provider detection

For an LLM proxy, Apigee resolves the response format from the
proxy's target URL:

| Target URL | Response envelope |
|---|---|
| Agent Platform OpenAI-compatible endpoint (`.../endpoints/openapi/chat/completions`), or OpenAI (`https://api.openai.com/v1/chat/completions`) | OpenAI Chat Completions |
| Agent Platform Gemini native endpoint (`.../publishers/google/models/MODEL:generateContent`) | Gemini `generateContent` |
| Agent Platform Anthropic native endpoint (`.../publishers/anthropic/models/MODEL:rawPredict`) | Anthropic Messages |

> [!NOTE]
> **Note:** The LLM template's **Gemini** option targets the Agent Platform OpenAI-compatible endpoint, so a Gemini proxy created from the template returns responses in the OpenAI Chat Completions format. To return responses in the Gemini `generateContent` format, target the Gemini native endpoint.

If the target URL does not match a known provider---for example, an
OpenAI-compatible endpoint on your own infrastructure, or a target URL that is
resolved dynamically at runtime---declare the response format explicitly with
the `defaultFormat` attribute:

```xml
<ProxyOperationMode defaultFormat="OPENAI_CHAT_COMPLETIONS">LLM</ProxyOperationMode>
```

Each `defaultFormat` value names the response envelope that the
formatter emits, not a backend provider. Supported values are
`OPENAI_CHAT_COMPLETIONS`, `GEMINI_GENERATE_CONTENT`,
`GEMINI_CHAT_COMPLETIONS`, and `ANTHROPIC_MESSAGES`. If a
static target URL does not match a known provider and no `defaultFormat`
is set, the deployment is rejected so that the proxy cannot reach a state where the
response format is undefined.

> [!NOTE]
> **Note:** Set `defaultFormat` if you want Apigee to format faults that are raised on the **request** path (for example, by the Quota, VerifyAPIKey, OAuth, or SpikeArrest policies). On the request path, Apigee hasn't routed to the target yet, so it can't resolve the response format from the target URL. Without `defaultFormat`, these request-path faults return a generic error instead of the provider's native envelope---even when the target URL is a recognized provider.

### Observability

For every response that the formatter produces, Apigee sets the
`X-Apigee-LLM-Intercept-Reason` response header, which identifies why
the gateway generated the response (for example, a custom message or a policy
fault). Apigee also sets the `llmresponse.source` and
`llmresponse.content` flow variables, which you can read from
downstream policies or a
[Debug session](https://docs.cloud.google.com/apigee/docs/api-platform/debug/trace.md.txt).

## Limitations

- The LLM template configures the standard chat or completions endpoint for each provider. To use a different endpoint, edit the proxy's target URL.
- Only text models are offered in the model picker.

## What's next

- [Create an LLM
  API proxy](https://docs.cloud.google.com/apigee/docs/api-platform/develop/create-llm-proxy)
- [AI gateway
  capabilities](https://docs.cloud.google.com/apigee/docs/api-platform/get-started/ai-capabilities)