# AI Proxy

The `ai-proxy` plugin forwards LLM and embedding requests to OpenAI, DeepSeek, Anthropic, Gemini, Gemini Enterprise Agent Platform, and other compatible providers. A common plugin configuration applies the provider-specific authentication, endpoint, and request format. To load balance across multiple AI endpoints, use [`ai-proxy-multi`](https://docs.api7.ai/hub/ai-proxy-multi.md).

The plugin sends requests directly to the selected provider endpoint. An upstream is not required. If the route or service has an upstream configured, the plugin bypasses it, so its health status does not affect these requests.

Before forwarding a request, the plugin identifies the client protocol from the request URI and body. Protocol conversion applies when the client uses Anthropic Messages but the selected provider supports OpenAI Chat Completions instead of native Anthropic Messages. The plugin converts the client request to OpenAI format and the backend response to Anthropic format. This conversion supports only a subset of Anthropic Messages. See [Protocol Reference](https://docs.api7.ai/hub/ai-proxy-protocol-reference.md?plugin=ai-proxy) for detection rules, field mappings, release boundaries, and limitations.

The plugin can also record LLM request information in the access log, not the error log, including token usage, model, and time to first response. Logging plugins can consume these entries.

## Examples[​](#examples "Direct link to Examples")

The following examples configure `ai-proxy` for common provider and protocol scenarios.

### Proxy to OpenAI[​](#proxy-to-openai "Direct link to Proxy to OpenAI")

The following example configures `ai-proxy` on a route that sends chat requests to OpenAI.

Obtain an OpenAI [API key](https://platform.openai.com/api-keys) and optionally save it to an environment variable:

```
export OPENAI_API_KEY="<OPENAI_API_KEY>"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-route",

    "uri": "/anything",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "openai",

        "auth": {

          "header": {

            "Authorization": "Bearer $OPENAI_API_KEY"

          }

        },

        "options":{

          "model": "gpt-4.1-mini"

        }

      }

    }

  }

EOF
```

❶ Specify the provider to be `openai`.

❷ Attach OpenAI API key in the `Authorization` header.

❸ Specify the name of the model.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: openai-service

    labels:

      docs-example: ai-proxy-openai

    routes:

      - name: openai-route

        uris:

          - /anything

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: openai

            auth:

              header:

                Authorization: Bearer ${OPENAI_API_KEY}

            options:

              model: gpt-4.1-mini

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-openai
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-openai
```

❶ Specify the provider to be `openai`.

❷ Attach OpenAI API key in the `Authorization` header.

❸ Specify the name of the model.

* Gateway API
* APISIX CRD

ai-proxy-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: openai

        auth:

          header:

            Authorization: "Bearer <OPENAI_API_KEY>"

        options:

          model: gpt-4.1-mini

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: openai-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /anything

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-ic.yaml
```

❶ Specify the provider to be `openai`.

❷ Attach OpenAI API key in the `Authorization` header.

❸ Specify the name of the model.

ai-proxy-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: openai-route

spec:

  ingressClassName: apisix

  http:

    - name: openai-route

      match:

        paths:

          - /anything

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: openai

          auth:

            header:

              Authorization: "Bearer <OPENAI_API_KEY>"

          options:

            model: gpt-4.1-mini
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-ic.yaml
```

❶ Specify the provider to be `openai`.

❷ Attach OpenAI API key in the `Authorization` header.

❸ Specify the name of the model.

The ADC and Gateway API tabs include a conventional backend. When the plugin handles the request itself, the backend is not contacted. Verify the plugin-specific result below; a backend response alone does not confirm that the plugin ran.

Send a POST request to the route with a system prompt and a sample user question in the request body:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  ...,

  "model": "gpt-4.1-mini-2025-04-14",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "1+1 equals 2.",

        "refusal": null

      },

      "logprobs": null,

      "finish_reason": "stop"

    }

  ],

  ...

}
```

If the LLM upstream returns `429` or a `5xx` response, the client receives the upstream status, response body, and `Content-Type`. This preserves any provider error details.

### Proxy to DeepSeek[​](#proxy-to-deepseek "Direct link to Proxy to DeepSeek")

The following example configures `ai-proxy` to send chat requests to DeepSeek.

Obtain the DeepSeek API key and optionally save it to an environment variable:

```
export DEEPSEEK_API_KEY="<DEEPSEEK_API_KEY>"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-route",

    "uri": "/anything",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "deepseek",

        "auth": {

          "header": {

            "Authorization": "Bearer $DEEPSEEK_API_KEY"

          }

        },

        "options": {

          "model": "deepseek-chat"

        }

      }

    }

  }

EOF
```

❶ Specify the provider to be `deepseek`, so that the plugin will proxy requests to `https://api.deepseek.com/chat/completions`.

❷ Attach DeepSeek API key in the `Authorization` header.

❸ Specify the name of the model.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: deepseek-service

    labels:

      docs-example: ai-proxy-deepseek

    routes:

      - name: deepseek-route

        uris:

          - /anything

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: deepseek

            auth:

              header:

                Authorization: Bearer ${DEEPSEEK_API_KEY}

            options:

              model: deepseek-chat

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-deepseek
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-deepseek
```

❶ Specify the provider to be `deepseek`, so that the plugin will proxy requests to `https://api.deepseek.com/chat/completions`.

❷ Attach DeepSeek API key in the `Authorization` header.

❸ Specify the name of the model.

* Gateway API
* APISIX CRD

deepseek-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: deepseek

        auth:

          header:

            Authorization: "Bearer <DEEPSEEK_API_KEY>"

        options:

          model: deepseek-chat

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: deepseek-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /anything

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f deepseek-ic.yaml
```

❶ Specify the provider to be `deepseek`, so that the plugin will proxy requests to `https://api.deepseek.com/chat/completions`.

❷ Attach DeepSeek API key in the `Authorization` header.

❸ Specify the name of the model.

deepseek-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: deepseek-route

spec:

  ingressClassName: apisix

  http:

    - name: deepseek-route

      match:

        paths:

          - /anything

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: deepseek

          auth:

            header:

              Authorization: "Bearer <DEEPSEEK_API_KEY>"

          options:

            model: deepseek-chat
```

Apply the configuration to your cluster:

```
kubectl apply -f deepseek-ic.yaml
```

❶ Specify the provider to be `deepseek`, so that the plugin will proxy requests to `https://api.deepseek.com/chat/completions`.

❷ Attach DeepSeek API key in the `Authorization` header.

❸ Specify the name of the model.

Send a POST request to the route with a sample question in the request body:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      {

        "role": "system",

        "content": "You are an AI assistant that helps people find information."

      },

      {

        "role": "user",

        "content": "Write me a 50-word introduction for Apache APISIX."

      }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  ...

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "Apache APISIX is a dynamic, real-time, high-performance API gateway and cloud-native platform. It provides rich traffic management features like load balancing, dynamic upstream, canary release, circuit breaking, authentication, observability, and more. Designed for microservices and serverless architectures, APISIX ensures scalability, security, and seamless integration with modern DevOps workflows."

      },

      "logprobs": null,

      "finish_reason": "stop"

    }

  ],

  ...

}
```

### Proxy to Azure OpenAI[​](#proxy-to-azure-openai "Direct link to Proxy to Azure OpenAI")

The following example sends Chat Completions requests to an Azure OpenAI deployment through its v1 API.

Obtain the Azure OpenAI API key and optionally save it to an environment variable:

```
export AZ_OPENAI_API_KEY="<AZURE_OPENAI_API_KEY>"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-route",

    "uri": "/anything",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "openai-compatible",

        "auth": {

          "header": {

            "api-key": "$AZ_OPENAI_API_KEY"

          }

        },

        "options":{

          "model": "<AZURE_OPENAI_DEPLOYMENT>"

        },

        "override": {

          "endpoint": "https://<AZURE_OPENAI_RESOURCE>.openai.azure.com/openai/v1/chat/completions"

        }

      }

    }

  }

EOF
```

❶ Set the provider to `openai-compatible` so the deployment name remains in the v1 request body.

❷ Attach Azure OpenAI API key in the `api-key` header.

❸ Specify the Azure OpenAI deployment name.

❹ Specify the Azure OpenAI v1 Chat Completions endpoint.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: azure-openai-service

    labels:

      docs-example: ai-proxy-azure-openai

    routes:

      - name: azure-openai-route

        uris:

          - /anything

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: openai-compatible

            auth:

              header:

                api-key: ${AZ_OPENAI_API_KEY}

            options:

              model: <AZURE_OPENAI_DEPLOYMENT>

            override:

              endpoint: "https://<AZURE_OPENAI_RESOURCE>.openai.azure.com/openai/v1/chat/completions"

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-azure-openai
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-azure-openai
```

❶ Set the provider to `openai-compatible` so the deployment name remains in the v1 request body.

❷ Attach Azure OpenAI API key in the `api-key` header.

❸ Specify the Azure OpenAI deployment name.

❹ Specify the Azure OpenAI v1 Chat Completions endpoint.

* Gateway API
* APISIX CRD

azure-openai-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: openai-compatible

        auth:

          header:

            api-key: "<AZURE_OPENAI_API_KEY>"

        options:

          model: <AZURE_OPENAI_DEPLOYMENT>

        override:

          endpoint: "https://<AZURE_OPENAI_RESOURCE>.openai.azure.com/openai/v1/chat/completions"

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: azure-openai-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /anything

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f azure-openai-ic.yaml
```

❶ Set the provider to `openai-compatible` so the deployment name remains in the v1 request body.

❷ Attach Azure OpenAI API key in the `api-key` header.

❸ Specify the Azure OpenAI deployment name.

❹ Specify the Azure OpenAI v1 Chat Completions endpoint.

azure-openai-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: azure-openai-route

spec:

  ingressClassName: apisix

  http:

    - name: azure-openai-route

      match:

        paths:

          - /anything

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: openai-compatible

          auth:

            header:

              api-key: "<AZURE_OPENAI_API_KEY>"

          options:

            model: <AZURE_OPENAI_DEPLOYMENT>

          override:

            endpoint: "https://<AZURE_OPENAI_RESOURCE>.openai.azure.com/openai/v1/chat/completions"
```

Apply the configuration to your cluster:

```
kubectl apply -f azure-openai-ic.yaml
```

❶ Set the provider to `openai-compatible` so the deployment name remains in the v1 request body.

❷ Attach Azure OpenAI API key in the `api-key` header.

❸ Specify the Azure OpenAI deployment name.

❹ Specify the Azure OpenAI v1 Chat Completions endpoint.

Send a POST request to the route with a sample question in the request body:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      {

        "role": "system",

        "content": "You are an AI assistant that helps people find information."

      },

      {

        "role": "user",

        "content": "Write me a 50-word introduction for Apache APISIX."

      }

    ],

    "max_tokens": 800,

    "temperature": 0.7,

    "frequency_penalty": 0,

    "presence_penalty": 0,

    "top_p": 0.95,

    "stop": null

  }'
```

You should receive a response similar to the following:

```
{

  "choices": [

    {

      ...,

      "message": {

        "content": "Apache APISIX is a modern, cloud-native API gateway built to handle high-performance and low-latency use cases. It offers a wide range of features, including load balancing, rate limiting, authentication, and dynamic routing, making it an ideal choice for microservices and cloud-native architectures.",

        "role": "assistant"

      }

    }

  ],

  ...

}
```

### Proxy to Gemini[​](#proxy-to-gemini "Direct link to Proxy to Gemini")

The following example sends chat requests to the Gemini API. Gemini support was introduced in API7 Enterprise 3.9.2 and APISIX 3.15.0.

[Obtain a Gemini API key](https://ai.google.dev/gemini-api/docs/api-key) and optionally save it to an environment variable:

```
export GEMINI_API_KEY="<GEMINI_API_KEY>"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-gemini-route",

    "uri": "/anything",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "gemini",

        "auth": {

          "header": {

            "Authorization": "Bearer $GEMINI_API_KEY"

          }

        },

        "options": {

          "model": "gemini-3.6-flash"

        }

      }

    }

  }

EOF
```

❶ Specify the provider to be `gemini`.

❷ Replace with your Gemini API key in the `Authorization` header.

❸ Specify the name of the Gemini model.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: gemini-service

    labels:

      docs-example: ai-proxy-gemini

    routes:

      - name: gemini-route

        uris:

          - /anything

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: gemini

            auth:

              header:

                Authorization: Bearer ${GEMINI_API_KEY}

            options:

              model: gemini-3.6-flash

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-gemini
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-gemini
```

❶ Specify the provider to be `gemini`.

❷ Replace with your Gemini API key in the `Authorization` header.

❸ Specify the name of the Gemini model.

* Gateway API
* APISIX CRD

gemini-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: gemini

        auth:

          header:

            Authorization: "Bearer <GEMINI_API_KEY>"

        options:

          model: gemini-3.6-flash

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: gemini-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /anything

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f gemini-ic.yaml
```

❶ Specify the provider to be `gemini`.

❷ Replace with your Gemini API key in the `Authorization` header.

❸ Specify the name of the Gemini model.

gemini-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: gemini-route

spec:

  ingressClassName: apisix

  http:

    - name: gemini-route

      match:

        paths:

          - /anything

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: gemini

          auth:

            header:

              Authorization: "Bearer <GEMINI_API_KEY>"

          options:

            model: gemini-3.6-flash
```

Apply the configuration to your cluster:

```
kubectl apply -f gemini-ic.yaml
```

❶ Specify the provider to be `gemini`.

❷ Replace with your Gemini API key in the `Authorization` header.

❸ Specify the name of the Gemini model.

about model endpoint

The configuration above proxies requests to the chat completion endpoint at `https://generativelanguage.googleapis.com/v1beta/openai/chat/completions`. To proxy requests to an embeddings model, explicitly configure the embeddings model endpoint in the `override` field.

Send a POST request to the route with a system prompt and a sample user question in the request body:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      { "role": "system", "content": "You are a helpful AI assistant" },

      { "role": "user", "content": "What is the capital of France?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  "choices": [

    {

      "finish_reason": "stop",

      "index": 0,

      "message": {

        "content": "The capital of France is **Paris**.",

        "role": "assistant"

      }

    }

  ],

  "model": "gemini-3.6-flash",

  "object": "chat.completion",

  "usage": {

    "completion_tokens": 8,

    "prompt_tokens": 15,

    "total_tokens": 41

  },

  ...

}
```

### Proxy to Gemini Enterprise Agent Platform Chat Completions[​](#proxy-to-gemini-enterprise-agent-platform-chat-completions "Direct link to Proxy to Gemini Enterprise Agent Platform Chat Completions")

The following example sends chat requests to Gemini Enterprise Agent Platform, previously documented as Vertex AI, using a Google Cloud service account. The released plugin provider identifier remains `vertex-ai`. This provider was introduced in API7 Enterprise 3.9.2 and APISIX 3.15.0.

Before proceeding:

* Follow the [Agent Platform setup](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/start) instructions to enable billing and the Agent Platform API.
* Create a service account, grant it the Agent Platform User (`roles/aiplatform.user`) role, and [create a service-account key](https://docs.cloud.google.com/iam/docs/keys-create-delete) in JSON format. The plugin requires the downloaded key and does not discover Application Default Credentials or Workload Identity Federation credentials.

Your credentials file should look similar to the following:

credentials.json

```
{

  "type": "service_account",

  "project_id": "<GCP_PROJECT_ID>",

  "private_key_id": "...",

  "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",

  "client_email": "<SERVICE_ACCOUNT_EMAIL>",

  "client_id": "....",

  "auth_uri": "https://accounts.google.com/o/oauth2/auth",

  "token_uri": "https://oauth2.googleapis.com/token",

  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",

  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/<URL_ENCODED_SERVICE_ACCOUNT_EMAIL>",

  "universe_domain": "googleapis.com"

}
```

Save the raw JSON for the ADC example and a JSON-encoded string for the Admin API example:

```
export GCP_SA_JSON="$(cat credentials.json)"

export GCP_SA_JSON_STRING="$(jq -Rs . < credentials.json)"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-vertex-ai-route",

    "uri": "/anything",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "vertex-ai",

        "auth": {

          "gcp": {

            "service_account_json": $GCP_SA_JSON_STRING

          }

        },

        "override": {

          "endpoint": "https://aiplatform.googleapis.com/v1beta1/projects/<GCP_PROJECT_ID>/locations/global/endpoints/openapi/chat/completions"

        },

        "options": {

          "model": "google/gemini-3.5-flash"

        }

      }

    }

  }

EOF
```

❶ Specify the provider to be `vertex-ai`.

❷ Provide the service account credentials as a JSON string.

❸ Replace `<GCP_PROJECT_ID>` in the documented global Chat Completions endpoint with your project ID.

❹ Specify an Agent Platform model that supports Chat Completions on the global endpoint. The example uses `google/gemini-3.5-flash`, which supports the default Standard PayGo consumption mode on `global`.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: vertex-ai-service

    labels:

      docs-example: ai-proxy-vertex-chat

    routes:

      - name: vertex-ai-route

        uris:

          - /anything

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: vertex-ai

            auth:

              gcp:

                service_account_json: ${GCP_SA_JSON}

            override:

              endpoint: https://aiplatform.googleapis.com/v1beta1/projects/<GCP_PROJECT_ID>/locations/global/endpoints/openapi/chat/completions

            options:

              model: google/gemini-3.5-flash

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-vertex-chat
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-vertex-chat
```

❶ Specify the provider to be `vertex-ai`.

❷ Provide the service account credentials as a JSON string.

❸ Replace `<GCP_PROJECT_ID>` in the documented global Chat Completions endpoint with your project ID.

❹ Specify an Agent Platform model that supports Chat Completions on the global endpoint. The example uses `google/gemini-3.5-flash`, which supports the default Standard PayGo consumption mode on `global`.

* Gateway API
* APISIX CRD

vertex-ai-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: vertex-ai

        auth:

          gcp:

            service_account_json: '{"type":"service_account","project_id":"<GCP_PROJECT_ID>","private_key_id":"...","private_key":"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----","client_email":"<SERVICE_ACCOUNT_EMAIL>","client_id":"...","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/<URL_ENCODED_SERVICE_ACCOUNT_EMAIL>","universe_domain":"googleapis.com"}'

        override:

          endpoint: https://aiplatform.googleapis.com/v1beta1/projects/<GCP_PROJECT_ID>/locations/global/endpoints/openapi/chat/completions

        options:

          model: google/gemini-3.5-flash

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: vertex-ai-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /anything

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f vertex-ai-ic.yaml
```

❶ Specify the provider to be `vertex-ai`.

❷ Provide the service account credentials as a JSON string.

❸ Replace `<GCP_PROJECT_ID>` in the documented global Chat Completions endpoint with your project ID.

❹ Specify an Agent Platform model that supports Chat Completions on the global endpoint. The example uses `google/gemini-3.5-flash`, which supports the default Standard PayGo consumption mode on `global`.

vertex-ai-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: vertex-ai-route

spec:

  ingressClassName: apisix

  http:

    - name: vertex-ai-route

      match:

        paths:

          - /anything

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: vertex-ai

          auth:

            gcp:

              service_account_json: '{"type":"service_account","project_id":"<GCP_PROJECT_ID>","private_key_id":"...","private_key":"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----","client_email":"<SERVICE_ACCOUNT_EMAIL>","client_id":"...","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/<URL_ENCODED_SERVICE_ACCOUNT_EMAIL>","universe_domain":"googleapis.com"}'

          override:

            endpoint: https://aiplatform.googleapis.com/v1beta1/projects/<GCP_PROJECT_ID>/locations/global/endpoints/openapi/chat/completions

          options:

            model: google/gemini-3.5-flash
```

Apply the configuration to your cluster:

```
kubectl apply -f vertex-ai-ic.yaml
```

❶ Specify the provider to be `vertex-ai`.

❷ Provide the service account credentials as a JSON string.

❸ Replace `<GCP_PROJECT_ID>` in the documented global Chat Completions endpoint with your project ID.

❹ Specify an Agent Platform model that supports Chat Completions on the global endpoint. The example uses `google/gemini-3.5-flash`, which supports the default Standard PayGo consumption mode on `global`.

Send a POST request to the route with a system prompt and a sample user question in the request body:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  "choices": [

    {

      "message": {

        "role": "assistant",

        "content": "1 + 1 = 2\n"

      },

      "index": 0,

      "logprobs": null,

      "finish_reason": "stop"

    }

  ],

  "usage": {

    "completion_tokens": 8,

    "extra_properties": {

      "google": {

        "traffic_type": "ON_DEMAND"

      }

    },

    "total_tokens": 19,

    "prompt_tokens": 11

  },

  "object": "chat.completion",

  "model": "google/gemini-3.5-flash",

  ...

}
```

### Proxy to Agent Platform Embedding Models[​](#proxy-to-agent-platform-embedding-models "Direct link to Proxy to Agent Platform Embedding Models")

The following example sends embedding requests to Gemini Enterprise Agent Platform using a Google Cloud service account. The released plugin provider identifier remains `vertex-ai`. This provider was introduced in API7 Enterprise 3.9.2 and APISIX 3.15.0.

Before proceeding:

* Follow the [Agent Platform setup](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/start) instructions to enable billing and the Agent Platform API.
* Create a service account, grant it the Agent Platform User (`roles/aiplatform.user`) role, and [create a service-account key](https://docs.cloud.google.com/iam/docs/keys-create-delete) in JSON format. The plugin requires the downloaded key and does not discover Application Default Credentials or Workload Identity Federation credentials.

Your credentials file should look similar to the following:

credentials.json

```
{

  "type": "service_account",

  "project_id": "<GCP_PROJECT_ID>",

  "private_key_id": "...",

  "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",

  "client_email": "<SERVICE_ACCOUNT_EMAIL>",

  "client_id": "....",

  "auth_uri": "https://accounts.google.com/o/oauth2/auth",

  "token_uri": "https://oauth2.googleapis.com/token",

  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",

  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/<URL_ENCODED_SERVICE_ACCOUNT_EMAIL>",

  "universe_domain": "googleapis.com"

}
```

Save the raw JSON for the ADC example and a JSON-encoded string for the Admin API example:

```
export GCP_SA_JSON="$(cat credentials.json)"

export GCP_SA_JSON_STRING="$(jq -Rs . < credentials.json)"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-vertex-ai-embeddings-route",

    "uri": "/embeddings",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "vertex-ai",

        "auth": {

          "gcp": {

            "service_account_json": $GCP_SA_JSON_STRING

          }

        },

        "provider_conf": {

          "project_id": "<GCP_PROJECT_ID>",

          "region": "us-central1"

        },

        "options": {

          "model": "gemini-embedding-001"

        }

      }

    }

  }

EOF
```

❶ Specify the provider to be `vertex-ai`.

❷ Provide the service account credentials as a JSON string.

❸ Replace with your Agent Platform project ID and location.

❹ Specify the Agent Platform Gemini embedding model.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: vertex-ai-embeddings-service

    labels:

      docs-example: ai-proxy-vertex-embeddings

    routes:

      - name: vertex-ai-embeddings-route

        uris:

          - /embeddings

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: vertex-ai

            auth:

              gcp:

                service_account_json: ${GCP_SA_JSON}

            provider_conf:

              project_id: <GCP_PROJECT_ID>

              region: us-central1

            options:

              model: gemini-embedding-001

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-vertex-embeddings
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-vertex-embeddings
```

❶ Specify the provider to be `vertex-ai`.

❷ Provide the service account credentials as a JSON string.

❸ Replace with your Agent Platform project ID and location.

❹ Specify the Agent Platform Gemini embedding model.

* Gateway API
* APISIX CRD

vertex-ai-embeddings-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: vertex-ai

        auth:

          gcp:

            service_account_json: '{"type":"service_account","project_id":"<GCP_PROJECT_ID>","private_key_id":"...","private_key":"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----","client_email":"<SERVICE_ACCOUNT_EMAIL>","client_id":"...","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/<URL_ENCODED_SERVICE_ACCOUNT_EMAIL>","universe_domain":"googleapis.com"}'

        provider_conf:

          project_id: <GCP_PROJECT_ID>

          region: us-central1

        options:

          model: gemini-embedding-001

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: vertex-ai-embeddings-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /embeddings

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f vertex-ai-embeddings-ic.yaml
```

❶ Specify the provider to be `vertex-ai`.

❷ Provide the service account credentials as a JSON string.

❸ Replace with your Agent Platform project ID and location.

❹ Specify the Agent Platform Gemini embedding model.

vertex-ai-embeddings-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: vertex-ai-embeddings-route

spec:

  ingressClassName: apisix

  http:

    - name: vertex-ai-embeddings-route

      match:

        paths:

          - /embeddings

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: vertex-ai

          auth:

            gcp:

              service_account_json: '{"type":"service_account","project_id":"<GCP_PROJECT_ID>","private_key_id":"...","private_key":"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----","client_email":"<SERVICE_ACCOUNT_EMAIL>","client_id":"...","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/<URL_ENCODED_SERVICE_ACCOUNT_EMAIL>","universe_domain":"googleapis.com"}'

          provider_conf:

            project_id: <GCP_PROJECT_ID>

            region: us-central1

          options:

            model: gemini-embedding-001
```

Apply the configuration to your cluster:

```
kubectl apply -f vertex-ai-embeddings-ic.yaml
```

❶ Specify the provider to be `vertex-ai`.

❷ Provide the service account credentials as a JSON string.

❸ Replace with your Agent Platform project ID and location.

❹ Specify the Agent Platform Gemini embedding model.

Send a POST request to the route with an input string:

```
curl "http://127.0.0.1:9080/embeddings" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "input": "hello world"

  }'
```

You should receive a response similar to the following:

```
{

  "model": "gemini-embedding-001",

  "usage": {

    "total_tokens": 2,

    "prompt_tokens": 2

  },

  "object": "list",

  "data": [

    {

      "index": 0,

      "object": "embedding",

      "embedding": [

        -0.0241838414222,

        0.0098769934847951,

        0.0074856607243419,

        -0.067302219569683,

        ...

      ]

    }

  ]

}
```

### Proxy to OpenAI Embedding Models[​](#proxy-to-openai-embedding-models "Direct link to Proxy to OpenAI Embedding Models")

The following example configures `ai-proxy` to send embedding requests to OpenAI.

Obtain an OpenAI [API key](https://platform.openai.com/api-keys) and optionally save it to an environment variable:

```
export OPENAI_API_KEY="<OPENAI_API_KEY>"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-route",

    "uri": "/embeddings",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "openai",

        "auth": {

          "header": {

            "Authorization": "Bearer $OPENAI_API_KEY"

          }

        },

        "options": {

          "model": "text-embedding-3-small",

          "encoding_format": "float"

        }

      }

    }

  }

EOF
```

❶ Select the `openai` provider. When the request body contains `input`, the plugin detects an Embeddings request and sends it to `https://api.openai.com/v1/embeddings`.

❷ Attach OpenAI API key in the `Authorization` header.

❸ Specify the name of the embedding model.

❹ Add an additional parameter `encoding_format` to configure returned embedding vector to be a list of floating point numbers.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: openai-embeddings-service

    labels:

      docs-example: ai-proxy-openai-embeddings

    routes:

      - name: openai-embeddings-route

        uris:

          - /embeddings

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: openai

            auth:

              header:

                Authorization: Bearer ${OPENAI_API_KEY}

            options:

              model: text-embedding-3-small

              encoding_format: float

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-openai-embeddings
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-openai-embeddings
```

❶ Select the `openai` provider. When the request body contains `input`, the plugin detects an Embeddings request and sends it to `https://api.openai.com/v1/embeddings`.

❷ Attach OpenAI API key in the `Authorization` header.

❸ Specify the name of the embedding model.

❹ Add an additional parameter `encoding_format` to configure returned embedding vector to be a list of floating point numbers.

* Gateway API
* APISIX CRD

openai-embeddings-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: openai

        auth:

          header:

            Authorization: "Bearer <OPENAI_API_KEY>"

        options:

          model: text-embedding-3-small

          encoding_format: float

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: openai-embeddings-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /embeddings

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f openai-embeddings-ic.yaml
```

❶ Select the `openai` provider. When the request body contains `input`, the plugin detects an Embeddings request and sends it to `https://api.openai.com/v1/embeddings`.

❷ Attach OpenAI API key in the `Authorization` header.

❸ Specify the name of the embedding model.

❹ Add an additional parameter `encoding_format` to configure returned embedding vector to be a list of floating point numbers.

openai-embeddings-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: openai-embeddings-route

spec:

  ingressClassName: apisix

  http:

    - name: openai-embeddings-route

      match:

        paths:

          - /embeddings

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: openai

          auth:

            header:

              Authorization: "Bearer <OPENAI_API_KEY>"

          options:

            model: text-embedding-3-small

            encoding_format: float
```

Apply the configuration to your cluster:

```
kubectl apply -f openai-embeddings-ic.yaml
```

❶ Select the `openai` provider. When the request body contains `input`, the plugin detects an Embeddings request and sends it to `https://api.openai.com/v1/embeddings`.

❷ Attach OpenAI API key in the `Authorization` header.

❸ Specify the name of the embedding model.

❹ Add an additional parameter `encoding_format` to configure returned embedding vector to be a list of floating point numbers.

Send a POST request to the route with an input string:

```
curl "http://127.0.0.1:9080/embeddings" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "input": "hello world"

  }'
```

You should receive a response similar to the following:

```
{

  "object": "list",

  "data": [

    {

      "object": "embedding",

      "index": 0,

      "embedding": [

        -0.0067144386,

        -0.039197803,

        0.034177095,

        0.028763203,

        -0.024785956,

        -0.04201061,

        ...

      ],

    }

  ],

  "model": "text-embedding-3-small",

  "usage": {

    "prompt_tokens": 2,

    "total_tokens": 2

  }

}
```

### Proxy to Anthropic[​](#proxy-to-anthropic "Direct link to Proxy to Anthropic")

The following example configures `ai-proxy` to send OpenAI-compatible Chat Completions requests to Claude through the Anthropic API.

Obtain an Anthropic [API key](https://console.anthropic.com/settings/keys) and optionally save it to an environment variable:

```
export ANTHROPIC_API_KEY="<ANTHROPIC_API_KEY>"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-anthropic-route",

    "uri": "/anything",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "anthropic",

        "auth": {

          "header": {

            "x-api-key": "$ANTHROPIC_API_KEY"

          }

        },

        "options": {

          "model": "claude-sonnet-5-5"

        }

      }

    }

  }

EOF
```

❶ Specify the provider to be `anthropic`.

❷ Attach Anthropic API key in the `x-api-key` header.

❸ Specify the name of the Anthropic model.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: anthropic-service

    labels:

      docs-example: ai-proxy-anthropic

    routes:

      - name: anthropic-route

        uris:

          - /anything

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: anthropic

            auth:

              header:

                x-api-key: ${ANTHROPIC_API_KEY}

            options:

              model: claude-sonnet-5-5

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-anthropic
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-anthropic
```

❶ Specify the provider to be `anthropic`.

❷ Attach Anthropic API key in the `x-api-key` header.

❸ Specify the name of the Anthropic model.

* Gateway API
* APISIX CRD

anthropic-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: anthropic

        auth:

          header:

            x-api-key: "<ANTHROPIC_API_KEY>"

        options:

          model: claude-sonnet-5-5

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: anthropic-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /anything

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f anthropic-ic.yaml
```

❶ Specify the provider to be `anthropic`.

❷ Attach Anthropic API key in the `x-api-key` header.

❸ Specify the name of the Anthropic model.

anthropic-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: anthropic-route

spec:

  ingressClassName: apisix

  http:

    - name: anthropic-route

      match:

        paths:

          - /anything

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: anthropic

          auth:

            header:

              x-api-key: "<ANTHROPIC_API_KEY>"

          options:

            model: claude-sonnet-5-5
```

Apply the configuration to your cluster:

```
kubectl apply -f anthropic-ic.yaml
```

❶ Specify the provider to be `anthropic`.

❷ Attach Anthropic API key in the `x-api-key` header.

❸ Specify the name of the Anthropic model.

Send a POST request to the route with a system prompt and a sample user question in the request body:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  "id": "chatcmpl-...",

  "object": "chat.completion",

  "model": "claude-sonnet-5-5",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "1+1 equals 2."

      },

      "finish_reason": "stop"

    }

  ],

  "usage": {

    "prompt_tokens": 19,

    "completion_tokens": 11,

    "total_tokens": 30

  }

}
```

### Convert Anthropic Requests to OpenAI-Compatible Backend[​](#convert-anthropic-requests-to-openai-compatible-backend "Direct link to Convert Anthropic Requests to OpenAI-Compatible Backend")

The following example configures the `ai-proxy` plugin to accept Anthropic Messages requests, convert them to OpenAI Chat Completions, and forward them to an OpenAI-compatible backend. Use this configuration when client applications send Anthropic-formatted requests but the backend uses an OpenAI-compatible API.

The `/v1/messages` URI suffix identifies the request as Anthropic Messages. Because this example configures an OpenAI-compatible provider, the plugin converts requests to OpenAI Chat Completions and converts responses back to Anthropic format.

Obtain an API key for your chosen OpenAI-compatible backend service and save it to an environment variable. This example uses OpenAI:

```
export BACKEND_API_KEY="<BACKEND_API_KEY>"
```

* Admin API
* ADC
* Ingress Controller

Create a route with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-anthropic-convert-route",

    "uri": "/v1/messages",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "openai",

        "auth": {

          "header": {

            "Authorization": "Bearer $BACKEND_API_KEY"

          }

        },

        "options": {

          "model": "gpt-4.1-mini"

        }

      }

    }

  }

EOF
```

❶ Use a URI ending in `/v1/messages` to identify the request as Anthropic Messages.

❷ Configure a provider that supports OpenAI Chat Completions. The plugin converts the Anthropic request before forwarding it.

❸ Specify the model name of the backend provider.

Create a route with the `ai-proxy` plugin:

adc.yaml

```
services:

  - name: anthropic-convert-service

    labels:

      docs-example: ai-proxy-anthropic-conversion

    routes:

      - name: anthropic-convert-route

        uris:

          - /v1/messages

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: openai

            auth:

              header:

                Authorization: Bearer ${BACKEND_API_KEY}

            options:

              model: gpt-4.1-mini

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-anthropic-conversion
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-anthropic-conversion
```

❶ Use a URI ending in `/v1/messages` to identify the request as Anthropic Messages.

❷ Configure a provider that supports OpenAI Chat Completions. The plugin converts the Anthropic request before forwarding it.

❸ Specify the model name of the backend provider.

* Gateway API
* APISIX CRD

anthropic-convert-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: openai

        auth:

          header:

            Authorization: "Bearer <BACKEND_API_KEY>"

        options:

          model: gpt-4.1-mini

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: anthropic-convert-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /v1/messages

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f anthropic-convert-ic.yaml
```

❶ Configure a provider that supports OpenAI Chat Completions. The plugin converts the Anthropic request before forwarding it.

❷ Specify the model name of the backend provider.

❸ Use a URI ending in `/v1/messages` to identify the request as Anthropic Messages.

anthropic-convert-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: anthropic-convert-route

spec:

  ingressClassName: apisix

  http:

    - name: anthropic-convert-route

      match:

        paths:

          - /v1/messages

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: openai

          auth:

            header:

              Authorization: "Bearer <BACKEND_API_KEY>"

          options:

            model: gpt-4.1-mini
```

Apply the configuration to your cluster:

```
kubectl apply -f anthropic-convert-ic.yaml
```

❶ Use a URI ending in `/v1/messages` to identify the request as Anthropic Messages.

❷ Configure a provider that supports OpenAI Chat Completions. The plugin converts the Anthropic request before forwarding it.

❸ Specify the model name of the backend provider.

Send a POST request to the route in Anthropic Messages API format:

```
curl "http://127.0.0.1:9080/v1/messages" -X POST \

  -H "Content-Type: application/json" \

  -H "x-api-key: ${BACKEND_API_KEY}" \

  -H "anthropic-version: 2023-06-01" \

  -d '{

    "model": "gpt-4.1-mini",

    "max_tokens": 1024,

    "messages": [

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

Although the request is sent in Anthropic format, it will be automatically converted to OpenAI format and forwarded to the backend. The response is converted back to Anthropic format:

```
{

  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",

  "type": "message",

  "role": "assistant",

  "content": [

    {

      "type": "text",

      "text": "1+1 equals 2."

    }

  ],

  "model": "gpt-4.1-mini",

  "stop_reason": "end_turn",

  "usage": {

    "input_tokens": 12,

    "output_tokens": 8

  }

}
```

This conversion covers common Anthropic Messages workflows: text messages, system prompts, streaming (SSE), and custom function tools. It converts the response back to Anthropic format.

The conversion supports a subset of the Anthropic Messages API, not an equivalent implementation. Some fields are approximated, and the plugin can drop unsupported fields without returning an error. See [Protocol Reference](https://docs.api7.ai/hub/ai-proxy-protocol-reference.md?plugin=ai-proxy#anthropic-to-openai-conversion) for the field-level mapping, the release boundaries, and the known limitations.

If your client and backend both support the Anthropic Messages API natively, use [Native Anthropic Messages API Pass-Through](#native-anthropic-messages-api-pass-through) instead. That mode skips the conversion and preserves Anthropic-specific fields.

### Native Anthropic Messages API Pass-Through[​](#native-anthropic-messages-api-pass-through "Direct link to Native Anthropic Messages API Pass-Through")

Native Anthropic Messages pass-through was introduced in API7 Enterprise 3.9.8 and APISIX 3.17.0.

The following example passes Anthropic Messages requests directly to an Anthropic backend without protocol conversion. Use this approach when both the client and backend use the native Anthropic format.

The [conversion example](#convert-anthropic-requests-to-openai-compatible-backend) translates Anthropic client requests to OpenAI format and backend responses to Anthropic format. Native pass-through performs neither protocol transformation, so it preserves all Anthropic-specific fields including cache token usage (`cache_creation_input_tokens`, `cache_read_input_tokens`).

Obtain an Anthropic [API key](https://console.anthropic.com/settings/keys) and save it to an environment variable:

```
export ANTHROPIC_API_KEY="<ANTHROPIC_API_KEY>"
```

Create a route with the `ai-proxy` plugin:

* Admin API
* ADC
* Ingress Controller

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-anthropic-native",

    "uri": "/v1/messages",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "anthropic",

        "auth": {

          "header": {

            "x-api-key": "$ANTHROPIC_API_KEY"

          }

        },

        "options": {

          "model": "claude-sonnet-5-5"

        }

      }

    }

  }

EOF
```

adc.yaml

```
services:

  - name: ai-proxy-anthropic-native-service

    labels:

      docs-example: ai-proxy-anthropic-passthrough

    routes:

      - name: ai-proxy-anthropic-native-route

        uris:

          - /v1/messages

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: anthropic

            auth:

              header:

                x-api-key: ${ANTHROPIC_API_KEY}

            options:

              model: claude-sonnet-5-5

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-anthropic-passthrough
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-anthropic-passthrough
```

* Gateway API
* APISIX CRD

ai-proxy-anthropic-native-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-anthropic-native-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: anthropic

        auth:

          header:

            x-api-key: <ANTHROPIC_API_KEY>

        options:

          model: claude-sonnet-5-5

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: ai-proxy-anthropic-native-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /v1/messages

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-anthropic-native-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-anthropic-native-ic.yaml
```

ai-proxy-anthropic-native-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: ai-proxy-anthropic-native-route

spec:

  ingressClassName: apisix

  http:

    - name: ai-proxy-anthropic-native-route

      match:

        paths:

          - /v1/messages

        methods:

          - POST

      plugins:

        - name: ai-proxy

          enable: true

          config:

            provider: anthropic

            auth:

              header:

                x-api-key: <ANTHROPIC_API_KEY>

            options:

              model: claude-sonnet-5-5
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-anthropic-native-ic.yaml
```

Send a request using the Anthropic Messages API format:

```
curl -i "http://127.0.0.1:9080/v1/messages" -X POST \

  -H "Content-Type: application/json" \

  -H "anthropic-version: 2023-06-01" \

  -d '{

    "model": "claude-sonnet-5-5",

    "messages": [

      {"role": "user", "content": "Hello, Claude!"}

    ],

    "max_tokens": 1024

  }'
```

The request is forwarded directly to the Anthropic API without format conversion. The response is returned in native Anthropic format, preserving all provider-specific fields.

### Proxy OpenAI Responses API[​](#proxy-openai-responses-api "Direct link to Proxy OpenAI Responses API")

OpenAI Responses API support was introduced in API7 Enterprise 3.9.8 and APISIX 3.17.0.

The following example configures `ai-proxy` for OpenAI Responses API requests (`POST /v1/responses`). The API supports built-in tools such as web search, file search, and computer use.

Obtain an [OpenAI API key](https://platform.openai.com/api-keys) and save it to an environment variable:

```
export OPENAI_API_KEY="<OPENAI_API_KEY>"
```

Responses and Embeddings requests both contain `input`. Keep the `/v1/responses` URI suffix so that the plugin identifies this request as Responses instead of Embeddings. See [Request Protocol Detection](https://docs.api7.ai/hub/ai-proxy-protocol-reference.md?plugin=ai-proxy#request-protocol-detection).

Create a route with the `ai-proxy` plugin:

* Admin API
* ADC
* Ingress Controller

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-responses-api",

    "uri": "/v1/responses",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "openai",

        "auth": {

          "header": {

            "Authorization": "Bearer $OPENAI_API_KEY"

          }

        },

        "options": {

          "model": "gpt-4.1"

        }

      }

    }

  }

EOF
```

adc.yaml

```
services:

  - name: ai-proxy-responses-api-service

    labels:

      docs-example: ai-proxy-openai-responses

    routes:

      - name: ai-proxy-responses-api-route

        uris:

          - /v1/responses

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: openai

            auth:

              header:

                Authorization: Bearer ${OPENAI_API_KEY}

            options:

              model: gpt-4.1

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-openai-responses
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-openai-responses
```

* Gateway API
* APISIX CRD

ai-proxy-responses-api-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-responses-api-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: openai

        auth:

          header:

            Authorization: "Bearer <OPENAI_API_KEY>"

        options:

          model: gpt-4.1

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: ai-proxy-responses-api-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /v1/responses

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-responses-api-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-responses-api-ic.yaml
```

ai-proxy-responses-api-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: ai-proxy-responses-api-route

spec:

  ingressClassName: apisix

  http:

    - name: ai-proxy-responses-api-route

      match:

        paths:

          - /v1/responses

        methods:

          - POST

      plugins:

        - name: ai-proxy

          enable: true

          config:

            provider: openai

            auth:

              header:

                Authorization: "Bearer <OPENAI_API_KEY>"

            options:

              model: gpt-4.1
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-responses-api-ic.yaml
```

Send a request using the OpenAI Responses API format:

```
curl -i "http://127.0.0.1:9080/v1/responses" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "model": "gpt-4.1",

    "input": "Explain API gateways in one sentence."

  }'
```

Send a streaming request:

```
curl "http://127.0.0.1:9080/v1/responses" -X POST \

  --no-buffer \

  -H "Content-Type: application/json" \

  -d '{

    "stream": true,

    "input": "Count from one to five."

  }'
```

❶ Disable cURL output buffering so that it displays each server-sent event as it arrives.

❷ Request a streaming response from OpenAI.

The stream contains typed events such as `response.output_text.delta` and ends with a `response.completed` event.

See [Failure Responses](https://docs.api7.ai/hub/ai-proxy-protocol-reference.md?plugin=ai-proxy#failure-responses) for empty and interrupted stream behavior.

Plugins that explicitly support the Responses request structure can be used on the same route. These include [`ai-prompt-decorator`](https://docs.api7.ai/hub/ai-prompt-decorator.md), [`ai-prompt-guard`](https://docs.api7.ai/hub/ai-prompt-guard.md), [`ai-rag`](https://docs.api7.ai/hub/ai-rag.md), and [`ai-aliyun-content-moderation`](https://docs.api7.ai/hub/ai-aliyun-content-moderation.md).

Each plugin handles `instructions` and `input` differently. Check its plugin page before adding it to a Responses route; plugins designed for Chat Completions do not automatically support the Responses format.

### Proxy to AWS Bedrock[​](#proxy-to-aws-bedrock "Direct link to Proxy to AWS Bedrock")

The `bedrock` provider signs and forwards requests to Amazon Bedrock's [Converse API](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html). It uses AWS Signature Version 4, so the plugin requires IAM credentials instead of an API key header. Bedrock Converse and ConverseStream are available in API7 Enterprise 3.9.12 and APISIX 3.17.0.

Obtain your AWS IAM credentials and save them to environment variables:

```
export AWS_ACCESS_KEY_ID="<AWS_ACCESS_KEY_ID>"

export AWS_SECRET_ACCESS_KEY="<AWS_SECRET_ACCESS_KEY>"
```

Create a route with the `ai-proxy` plugin configured for Bedrock:

* Admin API
* ADC
* Ingress Controller

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-bedrock",

    "uri": "/bedrock/converse",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "bedrock",

        "auth": {

          "aws": {

            "access_key_id": "$AWS_ACCESS_KEY_ID",

            "secret_access_key": "$AWS_SECRET_ACCESS_KEY"

          }

        },

        "provider_conf": {

          "region": "us-east-1"

        },

        "options": {

          "model": "global.anthropic.claude-haiku-5-5"

        }

      }

    }

  }

EOF
```

adc.yaml

```
services:

  - name: ai-proxy-bedrock-service

    labels:

      docs-example: ai-proxy-bedrock

    routes:

      - name: ai-proxy-bedrock-route

        uris:

          - /bedrock/converse

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: bedrock

            auth:

              aws:

                access_key_id: ${AWS_ACCESS_KEY_ID}

                secret_access_key: ${AWS_SECRET_ACCESS_KEY}

            provider_conf:

              region: us-east-1

            options:

              model: global.anthropic.claude-haiku-5-5

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-bedrock
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-bedrock
```

* Gateway API
* APISIX CRD

ai-proxy-bedrock-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-bedrock-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: bedrock

        auth:

          aws:

            access_key_id: <AWS_ACCESS_KEY_ID>

            secret_access_key: <AWS_SECRET_ACCESS_KEY>

        provider_conf:

          region: us-east-1

        options:

          model: global.anthropic.claude-haiku-5-5

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: ai-proxy-bedrock-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /bedrock/converse

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-bedrock-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-bedrock-ic.yaml
```

ai-proxy-bedrock-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: ai-proxy-bedrock-route

spec:

  ingressClassName: apisix

  http:

    - name: ai-proxy-bedrock-route

      match:

        paths:

          - /bedrock/converse

        methods:

          - POST

      plugins:

        - name: ai-proxy

          enable: true

          config:

            provider: bedrock

            auth:

              aws:

                access_key_id: <AWS_ACCESS_KEY_ID>

                secret_access_key: <AWS_SECRET_ACCESS_KEY>

            provider_conf:

              region: us-east-1

            options:

              model: global.anthropic.claude-haiku-5-5
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-bedrock-ic.yaml
```

The plugin uses the configured AWS credentials for SigV4 request signing.

Send a POST request to the route in Bedrock Converse format. The request URI must end with `/converse`:

```
curl "http://127.0.0.1:9080/bedrock/converse" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      {

        "role": "user",

        "content": [

          { "text": "Explain API gateways in one sentence." }

        ]

      }

    ],

    "inferenceConfig": {

      "maxTokens": 256

    }

  }'
```

The plugin forwards the request to the configured Bedrock model and applies SigV4 signing automatically.

To use streaming, add `"stream": true` to the request body:

```
curl "http://127.0.0.1:9080/bedrock/converse" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "stream": true,

    "messages": [

      {

        "role": "user",

        "content": [

          { "text": "Hello" }

        ]

      }

    ]

  }'
```

Streaming requests are routed to the `/converse-stream` endpoint and the binary AWS EventStream response is parsed and forwarded to the client.

### Proxy to Selected Model using Request Body Parameter[​](#proxy-to-selected-model-using-request-body-parameter "Direct link to Proxy to Selected Model using Request Body Parameter")

The following example routes requests on the same URI to OpenAI or DeepSeek based on the `model` field in the request body. The route uses a `post_arg.*` [variable](https://docs.api7.ai/api7-gateway/reference/built-in-variables.md) to read that field.

The example will use OpenAI and DeepSeek as the example LLM services. Obtain the OpenAI and DeepSeek API keys and save them to environment variables:

```
# replace with your API key

export OPENAI_API_KEY="<OPENAI_API_KEY>"

export DEEPSEEK_API_KEY="<DEEPSEEK_API_KEY>"
```

* Admin API
* ADC
* Ingress Controller

Create a route to the OpenAI API with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-openai-route",

    "uri": "/anything",

    "methods": ["POST"],

    "vars": [[ "post_arg.model", "==", "openai" ]],

    "plugins": {

      "ai-proxy": {

        "provider": "openai",

        "auth": {

          "header": {

            "Authorization": "Bearer $OPENAI_API_KEY"

          }

        },

        "options": {

          "model": "gpt-4.1-mini"

        }

      }

    }

  }

EOF
```

❶ Set the route URI to be `/anything`.

❷ Match the route to requests where the body parameter `model` is set to `openai`.

Create another route `/anything` to the DeepSeek API with the `ai-proxy` plugin:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-deepseek-route",

    "uri": "/anything",

    "methods": ["POST"],

    "vars": [[ "post_arg.model", "==", "deepseek" ]],

    "plugins": {

      "ai-proxy": {

        "provider": "deepseek",

        "auth": {

          "header": {

            "Authorization": "Bearer $DEEPSEEK_API_KEY"

          }

        },

        "options": {

          "model": "deepseek-chat"

        }

      }

    }

  }

EOF
```

❶ Set the route URI to be `/anything`, same as the previous route.

❷ Match the route to requests where the body parameter `model` is set to `deepseek`.

Create two routes with the `ai-proxy` plugin configured for different providers:

adc.yaml

```
services:

  - name: multi-model-service

    labels:

      docs-example: ai-proxy-request-model-routing

    routes:

      - name: openai-route

        uris:

          - /anything

        methods:

          - POST

        vars:

          - - post_arg.model

            - '=='

            - openai

        plugins:

          ai-proxy:

            provider: openai

            auth:

              header:

                Authorization: Bearer ${OPENAI_API_KEY}

            options:

              model: gpt-4.1-mini

      - name: deepseek-route

        uris:

          - /anything

        methods:

          - POST

        vars:

          - - post_arg.model

            - '=='

            - deepseek

        plugins:

          ai-proxy:

            provider: deepseek

            auth:

              header:

                Authorization: Bearer ${DEEPSEEK_API_KEY}

            options:

              model: deepseek-chat

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Review the diff for unexpected changes or deletions before syncing these services:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-request-model-routing
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-proxy-request-model-routing
```

❶ Set the route URI to be `/anything`.

❷ Match the route to requests where the body parameter `model` is set to `openai`.

❸ Set the route URI to be `/anything`, same as the previous route.

❹ Match the route to requests where the body parameter `model` is set to `deepseek`.

* Gateway API
* APISIX CRD

info

Body parameter matching is not supported in HTTPRoute. The supported matching mechanisms are `path`, `method`, `headers`, and `queryParams`. This example cannot be completed with Gateway API.

Create an `ApisixRoute` that matches requests based on the JSON request body field `model`:

ai-proxy-body-match.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixUpstream

metadata:

  namespace: aic

  name: httpbin-external-domain

spec:

  ingressClassName: apisix

  externalNodes:

    - type: Domain

      name: httpbin.org

---

apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: body-match-route

spec:

  ingressClassName: apisix

  http:

    - name: openai

      match:

        paths:

          - /anything

        exprs:

          - subject:

              scope: Body

              name: model

            op: Equal

            value: openai

      upstreams:

        - name: httpbin-external-domain

    - name: deepseek

      match:

        paths:

          - /anything

        exprs:

          - subject:

              scope: Body

              name: model

            op: Equal

            value: deepseek

      upstreams:

        - name: httpbin-external-domain
```

Apply the configuration to your cluster:

```
kubectl apply -f ai-proxy-body-match.yaml
```

Send a POST request to the route with `model` set to `openai`:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "model": "openai",

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  ...,

  "model": "gpt-4.1-mini-2025-04-14",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "1+1 equals 2.",

        "refusal": null

      },

      "logprobs": null,

      "finish_reason": "stop"

    }

  ],

  ...

}
```

Send a POST request to the route with `model` set to `deepseek`:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "model": "deepseek",

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  ...,

  "model": "deepseek-chat",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "The sum of 1 and 1 is 2. This is a basic arithmetic operation where you combine two units to get a total of two units."

      },

      "logprobs": null,

      "finish_reason": "stop"

    }

  ],

  ...

}
```

You can also configure `post_arg.*` to fetch nested request body parameter. For instance, if the request format is:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "model": {

      "name": "openai"

    },

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

You can configure the `vars` on the route to be `[[ "post_arg.model.name", "==", "openai" ]]`.

For more information on the expressions, see [APISIX Expressions](https://docs.api7.ai/api7-gateway/reference/expressions.md).

### Include LLM Information in Access Log[​](#include-llm-information-in-access-log "Direct link to Include LLM Information in Access Log")

The following example adds LLM request information to the gateway access log for analytics and auditing. In addition to NGINX variables, the following variables are available:

* `apisix_upstream_response_time`: Time taken for the gateway to send the request to the upstream service and receive the full response, in milliseconds. Error responses returned by the LLM upstream are also recorded in milliseconds. Available from API7 Enterprise 3.8.8.
* `request_type`: Type of request, where the value could be `traditional_http`, `ai_chat`, or `ai_stream`.
* `llm_time_to_first_token`: Duration from request sending to the first token received from the LLM service, in milliseconds. For an upstream error response, this is the duration until the error response was received. It remains `0` if the gateway could not reach the upstream.
* `llm_model`: LLM model name forwarded to the upstream LLM service.
* `request_llm_model`: LLM model name specified in the request.
* `llm_prompt_tokens`: Number of tokens in the prompt.
* `llm_completion_tokens`: Number of completion tokens in the response.
* `llm_content_risk_level`: Content risk level reported by an AI content moderation plugin. Introduced in APISIX 3.14.0.

The gateway's AI HTTP transport also populates the standard upstream variables `upstream_addr`, `upstream_status`, `apisix_upstream_response_time`, `upstream_scheme`, `upstream_host`, `upstream_uri`, and `upstream_response_length`.

These variables apply to streaming and non-streaming AI responses in API7 Enterprise 3.9.11 and later, and APISIX 3.17.0 and later. They are also populated for APISIX requests sent through the FFI client.

The following additional variables were introduced in API7 Enterprise 3.9.14 and 3.10.1, and in APISIX 3.18.0:

* `llm_total_tokens`: Total number of tokens used, including prompt and completion tokens.
* `llm_stream`: Whether the request was a streaming request, either `true` or `false`.
* `llm_has_tool_calls`: Whether the LLM response contains tool calls, either `true` or `false`.
* `llm_tool_count`: Number of tools provided in the request.
* `llm_end_user_id`: End-user identifier extracted from the request body, such as `user`, `safety_identifier`, or `metadata.user_id`.
* `llm_cache_read_input_tokens`: Number of prompt tokens served from the provider's prompt cache.
* `llm_cache_creation_input_tokens`: Number of prompt tokens written to the provider's prompt cache.
* `llm_reasoning_tokens`: Number of reasoning tokens used by reasoning models.

Token accounting

* Anthropic: `llm_prompt_tokens` includes native input, cache-read, and cache-creation tokens. `llm_total_tokens` also includes output tokens. Cache-inclusive accounting was introduced in APISIX 3.20.0 and API7 Enterprise 3.9.22 and 3.10.9.
* Bedrock: `llm_prompt_tokens` includes `inputTokens` plus cache-read and cache-write tokens. This cache-inclusive accounting was introduced in APISIX 3.20.0 and API7 Enterprise 3.10.9. API7 Enterprise 3.9.23 uses only `inputTokens`.

These normalized prompt totals feed logs, Prometheus metrics, and built-in `ai-rate-limiting` token strategies.

Access logs and logging plugins can use these variables directly. In APISIX 3.18.0 and API7 Enterprise 3.9.18 and 3.10.5, `logging.summaries` adds produced values to `llm_summary` without the `llm_` prefix. Values not produced for the request are omitted.

To record these values in access logs, add the LLM variables to the gateway access log format:

* Host or Docker
* Kubernetes (Helm)

Add or update this section in the gateway configuration file:

config.yaml

```
nginx_config:

  http:

    access_log_format: "$remote_addr - $remote_user [$time_local] $http_host \"$request_line\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_addr $upstream_status $apisix_upstream_response_time \"$upstream_scheme://$upstream_host$upstream_uri\" \"$apisix_request_id\" \"$request_type\" \"$llm_time_to_first_token\" \"$llm_model\" \"$request_llm_model\" \"$llm_prompt_tokens\" \"$llm_completion_tokens\" \"$llm_total_tokens\" \"$llm_stream\" \"$llm_has_tool_calls\" \"$llm_tool_count\" \"$llm_end_user_id\" \"$llm_cache_read_input_tokens\" \"$llm_cache_creation_input_tokens\" \"$llm_reasoning_tokens\""
```

Reload the gateway for configuration changes to take effect.

For the APISIX Helm chart, set the following values:

values.yaml

```
apisix:

  nginx:

    logs:

      accessLogFormat: "$remote_addr - $remote_user [$time_local] $http_host \"$request_line\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_addr $upstream_status $apisix_upstream_response_time \"$upstream_scheme://$upstream_host$upstream_uri\" \"$apisix_request_id\" \"$request_type\" \"$llm_time_to_first_token\" \"$llm_model\" \"$request_llm_model\" \"$llm_prompt_tokens\" \"$llm_completion_tokens\" \"$llm_total_tokens\" \"$llm_stream\" \"$llm_has_tool_calls\" \"$llm_tool_count\" \"$llm_end_user_id\" \"$llm_cache_read_input_tokens\" \"$llm_cache_creation_input_tokens\" \"$llm_reasoning_tokens\""
```

For the API7 Gateway Helm chart, set the following values:

values.yaml

```
logs:

  accessLogFormat: "$remote_addr - $remote_user [$time_local] $http_host \"$request_line\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_addr $upstream_status $apisix_upstream_response_time \"$upstream_scheme://$upstream_host$upstream_uri\" \"$apisix_request_id\" \"$request_type\" \"$llm_time_to_first_token\" \"$llm_model\" \"$request_llm_model\" \"$llm_prompt_tokens\" \"$llm_completion_tokens\" \"$llm_total_tokens\" \"$llm_stream\" \"$llm_has_tool_calls\" \"$llm_tool_count\" \"$llm_end_user_id\" \"$llm_cache_read_input_tokens\" \"$llm_cache_creation_input_tokens\" \"$llm_reasoning_tokens\""
```

Then apply the values file with the chart used for this gateway release:

```
helm upgrade <release-name> <chart-name> -n <namespace> -f values.yaml
```

Create a route by following [Proxy to OpenAI](#proxy-to-openai), then send a request:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "model": "gpt-4o-mini",

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

The plugin replaces the requested model with the configured `gpt-4.1-mini` model. You should receive a response similar to the following:

```
{

  ...,

  "model": "gpt-4.1-mini-2025-04-14",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "1+1 equals 2.",

        "refusal": null,

        "annotations": []

      },

      "logprobs": null,

      "finish_reason": "stop"

    }

  ],

  "usage": {

    "prompt_tokens": 23,

    "completion_tokens": 8,

    "total_tokens": 31,

    "prompt_tokens_details": {

      "cached_tokens": 0,

      "audio_tokens": 0

    },

    ...

  },

  "service_tier": "default",

  "system_fingerprint": null

}
```

In the gateway's access log, you should see a log entry similar to the following:

```
192.168.215.1 - - [<TIMESTAMP>] 127.0.0.1:9080 "POST /anything HTTP/1.1" 200 808 2.670 "-" "curl/8.6.0" - - 2670 "http://127.0.0.1:9080" "<REQUEST_ID>" "ai_chat" "2670" "gpt-4.1-mini" "gpt-4o-mini" "23" "8" "31" "false" "false" "0" "" "0" "0" "0"
```

The access log entry shows an upstream response time and time to first token of `2670` milliseconds. The request uses the `ai_chat` type, requests `gpt-4o-mini`, and is forwarded to `gpt-4.1-mini`. It uses 23 prompt tokens, 8 completion tokens, and 31 total tokens.

The remaining values show a non-streaming request with no tool calls, provided tools, end-user identifier, prompt-cache tokens, or reasoning tokens.

### Send AI Request Logs to Kafka[​](#send-ai-request-logs-to-kafka "Direct link to Send AI Request Logs to Kafka")

The following example sends AI request and response details, including model, token usage, and payloads, to Kafka. Complete the broker and `apisix-logs` topic setup in the [`kafka-logger`](https://docs.api7.ai/hub/kafka-logger.md) guide first.

* Admin API
* ADC
* Ingress Controller

Create a route to the LLM service and enable Kafka logging:

```
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d @- <<EOF

  {

    "id": "ai-proxy-openai-route",

    "uri": "/anything",

    "methods": ["POST"],

    "plugins": {

      "ai-proxy": {

        "provider": "openai",

        "auth": {

          "header": {

            "Authorization": "Bearer $OPENAI_API_KEY"

          }

        },

        "options": {

          "model": "gpt-4.1-mini"

        },

        "logging": {

          "summaries": true,

          "payloads": true

        }

      },

      "kafka-logger": {

        "brokers": [

          {

            "host": "kafka-server",

            "port": 9092

          }

        ],

        "kafka_topic": "apisix-logs",

        "key": "key1",

        "batch_max_size": 1

      }

    }

  }

EOF
```

❶ Log request LLM model, duration, request and response tokens.

❷ Log request and response payload.

❸ Update with your Kafka address.

❹ Update with your Kafka topic.

❺ Update with your Kafka key.

❻ Set to 1 to send the log entry immediately.

Create a route with both `ai-proxy` and `kafka-logger` plugins:

adc.yaml

```
services:

  - name: logging-service

    labels:

      docs-example: ai-kafka-logging

    routes:

      - name: logging-route

        uris:

          - /anything

        methods:

          - POST

        plugins:

          ai-proxy:

            provider: openai

            auth:

              header:

                Authorization: "Bearer ${OPENAI_API_KEY}"

            options:

              model: gpt-4.1-mini

            logging:

              summaries: true

              payloads: true

          kafka-logger:

            brokers:

              - host: kafka-server

                port: 9092

            kafka_topic: apisix-logs

            key: key1

            batch_max_size: 1

    upstream:

      type: roundrobin

      nodes:

        - host: httpbin.org

          port: 80

          weight: 1
```

Preview the changes to services with the example label:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-kafka-logging
```

Synchronize the reviewed changes:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=ai-kafka-logging
```

❶ Log request LLM model, duration, request and response tokens.

❷ Log request and response payload.

❸ Update with your Kafka address.

❹ Update with your Kafka topic.

❺ Update with your Kafka key.

❻ Set to 1 to send the log entry immediately.

* Gateway API
* APISIX CRD

logging-ic.yaml

```
apiVersion: v1

kind: Service

metadata:

  name: httpbin-external-domain

  namespace: aic

spec:

  type: ExternalName

  externalName: httpbin.org

  ports:

    - name: http

      port: 80

      protocol: TCP

---

apiVersion: apisix.apache.org/v1alpha1

kind: PluginConfig

metadata:

  namespace: aic

  name: ai-proxy-logging-plugin-config

spec:

  plugins:

    - name: ai-proxy

      config:

        provider: openai

        auth:

          header:

            Authorization: "Bearer <OPENAI_API_KEY>"

        options:

          model: gpt-4.1-mini

        logging:

          summaries: true

          payloads: true

    - name: kafka-logger

      config:

        brokers:

          - host: kafka-server.aic.svc

            port: 9092

        kafka_topic: apisix-logs

        key: key1

        batch_max_size: 1

---

apiVersion: gateway.networking.k8s.io/v1

kind: HTTPRoute

metadata:

  namespace: aic

  name: logging-route

spec:

  parentRefs:

    - name: apisix

  rules:

    - matches:

        - path:

            type: Exact

            value: /anything

          method: POST

      filters:

        - type: ExtensionRef

          extensionRef:

            group: apisix.apache.org

            kind: PluginConfig

            name: ai-proxy-logging-plugin-config

      backendRefs:

        - name: httpbin-external-domain

          port: 80
```

Apply the configuration to your cluster:

```
kubectl apply -f logging-ic.yaml
```

❶ Log request LLM model, duration, request and response tokens.

❷ Log request and response payload.

❸ Update with your Kafka address.

❹ Update with your Kafka topic.

❺ Update with your Kafka key.

❻ Set to 1 to send the log entry immediately.

logging-ic.yaml

```
apiVersion: apisix.apache.org/v2

kind: ApisixRoute

metadata:

  namespace: aic

  name: logging-route

spec:

  ingressClassName: apisix

  http:

    - name: logging-route

      match:

        paths:

          - /anything

        methods:

          - POST

      plugins:

      - name: ai-proxy

        enable: true

        config:

          provider: openai

          auth:

            header:

              Authorization: "Bearer <OPENAI_API_KEY>"

          options:

            model: gpt-4.1-mini

          logging:

            summaries: true

            payloads: true

      - name: kafka-logger

        enable: true

        config:

          brokers:

            - host: kafka-server.aic.svc

              port: 9092

          kafka_topic: apisix-logs

          key: key1

          batch_max_size: 1
```

Apply the configuration to your cluster:

```
kubectl apply -f logging-ic.yaml
```

❶ Log request LLM model, duration, request and response tokens.

❷ Log request and response payload.

❸ Update with your Kafka address.

❹ Update with your Kafka topic.

❺ Update with your Kafka key.

❻ Set to 1 to send the log entry immediately.

Send a POST request to the route:

```
curl "http://127.0.0.1:9080/anything" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  ...,

  "model": "gpt-4.1-mini-2025-04-14",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "1+1 equals 2.",

        "refusal": null

      },

      "logprobs": null,

      "finish_reason": "stop"

    }

  ],

  ...

}
```

In the Kafka topic, you should also see a log entry corresponding to the request with the LLM summary and request and response payloads:

```
{

  "llm_summary": {

    "model": "gpt-4.1-mini",

    "prompt_tokens": 23,

    "completion_tokens": 8,

    "total_tokens": 31

  },

  "llm_request": {

    "messages": [

      { "role": "system", "content": "You are a mathematician" },

      { "role": "user", "content": "What is 1+1?" }

    ],

    "stream": false

  },

  "llm_response_text": {

    "content": "1+1 equals 2."

  }

}
```

## Troubleshoot Tool Calls Returned as Text[​](#troubleshoot-tool-calls-returned-as-text "Direct link to Troubleshoot Tool Calls Returned as Text")

A response containing model-specific tool markers in `content` is text, even if it resembles a function call. For OpenAI Chat Completions, the client needs structured `tool_calls`; other protocols use their own structures, such as Anthropic `tool_use` blocks or Responses function-call items.

1. Confirm that the selected model and provider endpoint support native tool calling. Send the provider's supported tool definition and tool-choice settings. A prompt asking for a tool call does not enable an unsupported capability.
2. Send the same request directly to the provider and through the gateway. Keep the model, protocol, tool schema, and streaming setting identical. First compare non-streaming responses, then inspect streaming events if the problem occurs only with streaming.
3. If both responses contain markers only in text, check the model's serving template, tool parser, and the calling framework's protocol requirements. If only the gateway response differs, inspect protocol conversion and response-transforming plugins, and retain a redacted request and response for diagnosis.
4. In API7 Gateway, correlate `$llm_has_tool_calls` with the response and request ID. It indicates recognized tool calls in the response; a false value does not rule out tool-like text. `$llm_tool_count` instead counts tool definitions provided in the request. A positive count does not mean that the model called a tool. Avoid logging credentials or sensitive prompt content.

Configure the provider or framework to produce and consume the expected protocol. Do not execute arbitrary text as a tool call or assume that the gateway interprets a model's private markers.
