# Integrate Google Gemini

[Google Gemini](https://ai.google.dev/) provides access to Google's Gemini models through the AI Studio API. This guide shows how to route traffic to Gemini through API7 Gateway using the [`ai-proxy`](https://docs.api7.ai/hub/ai-proxy.md) plugin.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

* Install [Docker](https://docs.docker.com/get-docker/).

* Install [cURL](https://curl.se/) to send requests to the services for validation.

* Have a running API7 Gateway instance.

* Create a [token from the Dashboard](https://docs.api7.ai/api7-gateway/reference/obtain-dashboard-token.md) and save it to an environment variable:

  ```
  export API_KEY=your-dashboard-token   # replace with your Dashboard token
  ```

* Replace `{gateway_group_id}` with your gateway group ID. Use `default` if you are following the quickstart.

* If you are following the Admin API examples, create or reuse a service in API7 Gateway. If you do not have one yet, follow [Create or Reuse a Service](https://docs.api7.ai/api7-gateway/ai-gateway/get-started.md#create-or-reuse-a-service), then save its ID to an environment variable:

  ```
  export SERVICE_ID=your-service-id         # replace with your service ID
  ```

## Obtain a Gemini API Key[​](#obtain-a-gemini-api-key "Direct link to Obtain a Gemini API Key")

Generate an API key from [Google AI Studio](https://aistudio.google.com/apikey). Save the key to an environment variable:

```
export GEMINI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxx   # replace with your Gemini API key
```

## Configure the AI Proxy for Gemini[​](#configure-the-ai-proxy-for-gemini "Direct link to Configure the AI Proxy for Gemini")

Create a route with the [`ai-proxy`](https://docs.api7.ai/hub/ai-proxy.md) plugin:

* Admin API
* ADC

```
curl -k "https://localhost:7443/apisix/admin/routes/gemini-route?gateway_group_id={gateway_group_id}" -X PUT \

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

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

  --data-binary @- <<EOF

  {

    "name": "gemini-route",

    "service_id": "$SERVICE_ID",

    "paths": ["/gemini"],

    "plugins": {

      "ai-proxy": {

        "provider": "gemini",

        "auth": {

          "header": {

            "Authorization": "Bearer $GEMINI_API_KEY"

          }

        },

        "options": {

          "model": "gemini-3.6-flash"

        }

      }

    }

  }

EOF
```

❶ Set the provider to `gemini` to use the Google AI Studio API.

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

❸ Set the model to `gemini-3.6-flash`. See the [Gemini models page](https://ai.google.dev/gemini-api/docs/models) for available models.

adc.yaml

```
services:

  - name: Gemini Service

    routes:

      - uris:

          - /gemini

        name: gemini-route

        plugins:

          ai-proxy:

            provider: gemini

            auth:

              header:

                Authorization: "Bearer ${GEMINI_API_KEY}"

            options:

              model: gemini-3.6-flash

    labels:

      docs-example: gemini-service
```

❶ Set the provider to `gemini` to use the Google AI Studio API.

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

❸ Set the model to `gemini-3.6-flash`. See the [Gemini models page](https://ai.google.dev/gemini-api/docs/models) for available models.

Preview the changes owned by this example and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=gemini-service
```

Synchronize the reviewed configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=gemini-service
```

note

For enterprise workloads on Google Cloud, consider using [Vertex AI](https://docs.api7.ai/api7-gateway/ai-gateway/llm-providers/vertex-ai.md) instead. Vertex AI provides service account authentication, regional endpoints, and enterprise availability guarantees.

## Validate the Configuration[​](#validate-the-configuration "Direct link to Validate the Configuration")

Send a chat completion request:

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

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

  -d '{

    "messages": [

      { "role": "user", "content": "What is the speed of light?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  "id": "chatcmpl-abc123",

  "object": "chat.completion",

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

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "The speed of light in a vacuum is approximately 299,792,458 meters per second (about 186,282 miles per second)."

      },

      "finish_reason": "stop"

    }

  ],

  "usage": {

    "prompt_tokens": 8,

    "completion_tokens": 28,

    "total_tokens": 36

  }

}
```

To enable streaming responses, set `"stream": true` in the request body. Use the [`proxy-buffering`](https://docs.api7.ai/hub/proxy-buffering.md) plugin to disable NGINX `proxy_buffering` to avoid server-sent events (SSE) being buffered.

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have learned how to route traffic to Google Gemini through API7 Gateway. See the [Gemini API documentation](https://ai.google.dev/gemini-api/docs) to learn more about available models and capabilities.

* [Vertex AI](https://docs.api7.ai/api7-gateway/ai-gateway/llm-providers/vertex-ai.md) — Use Vertex AI for enterprise workloads with service account auth.
* [Multi-LLM Routing and Fallback](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/multi-llm-routing-and-fallback.md) — Combine Gemini with other providers.
