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

# Gemini CLI

> Route Gemini CLI and Google Gen AI SDK requests through the Orq.ai AI Gateway with native Google Generative Language compatibility.

[Gemini CLI](https://github.com/google-gemini/gemini-cli) connects to **Orq.ai** through the Google Generative Language-compatible endpoint. Keep native streaming and function calling while applying **AI Gateway** tracing, cost tracking, policies, and access controls.

## Prerequisites

* Active **Orq.ai** account
* [Orq.ai API key](/docs/ai-studio/organization/api-keys)

## Connect Gemini CLI

<Steps>
  <Step title="Install Gemini CLI">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    npm install -g @google/gemini-cli
    ```
  </Step>

  <Step title="Configure the endpoint and API key">
    Set the **Orq.ai** API key as `GEMINI_API_KEY`, then point Gemini CLI at the Google-compatible **AI Gateway** endpoint:

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    export GEMINI_API_KEY="<ORQ_API_KEY>"
    export GOOGLE_GEMINI_BASE_URL="https://my.orq.ai/v3/google"
    ```

    Replace `<ORQ_API_KEY>` with a key from [Workspace Settings > API Keys](https://my.orq.ai/settings/api-keys).
  </Step>

  <Step title="Start Gemini CLI">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    gemini
    ```

    If prompted, select **Gemini API Key** as the authentication method.

    If `gemini -p` reports `Invalid auth method selected`, add the authentication method to `~/.gemini/settings.json`:

    ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      "security": {
        "auth": {
          "selectedType": "gemini-api-key"
        }
      }
    }
    ```

    Send a prompt that reads a file or invokes another tool to verify streaming and function calling.
  </Step>
</Steps>

## Connect Google Gen AI SDKs

### Interactions API

Use the Interactions API for new model integrations. It provides a unified input and output format for model requests through `client.interactions.create`.

The gateway supports model interactions with text and image input, function tools and results, streaming, stored continuation, background execution, cancellation, and deletion. Managed agents, provider-hosted built-in tools, and non-text output modalities are not supported.

<Tabs>
  <Tab title="Node.js">
    ```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
    import { GoogleGenAI } from "@google/genai";

    const client = new GoogleGenAI({
      apiKey: process.env.ORQ_API_KEY,
      httpOptions: {
        baseUrl: "https://my.orq.ai/v3/google",
        apiVersion: "v1beta",
      },
    });

    const interaction = await client.interactions.create({
      model: "gemini-2.5-flash",
      input: "Explain the repository structure.",
    });

    const modelOutput = interaction.steps
      ?.filter((step) => step.type === "model_output")
      .at(-1);
    const text = modelOutput?.content
      ?.filter((part) => part.type === "text")
      .map((part) => part.text)
      .join("");

    console.log(text);

    const stream = await client.interactions.create({
      model: "gemini-2.5-flash",
      input: "Explain the repository structure.",
      stream: true,
    });

    for await (const event of stream) {
      console.log(event);
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    import os

    from google import genai
    from google.genai import types

    client = genai.Client(
        api_key=os.environ["ORQ_API_KEY"],
        http_options=types.HttpOptions(
            base_url="https://my.orq.ai/v3/google",
            api_version="v1beta",
        ),
    )

    interaction = client.interactions.create(
        model="gemini-2.5-flash",
        input="Explain the repository structure.",
    )

    model_output = next(
        step for step in reversed(interaction.steps)
        if step.type == "model_output"
    )
    text = "".join(
        part.text for part in model_output.content
        if part.type == "text"
    )

    print(text)

    stream = client.interactions.create(
        model="gemini-2.5-flash",
        input="Explain the repository structure.",
        stream=True,
    )

    for event in stream:
        print(event)
    ```
  </Tab>
</Tabs>

Gemini CLI continues to use the `generateContent` compatibility surface.

<Note>
  Exact `last_event_id` resume requires an interaction that was created with `stream: true`.
</Note>

### generateContent compatibility

Set the SDK base URL to `https://my.orq.ai/v3/google`. The SDK appends the `/v1beta/models/...` path.

<Tabs>
  <Tab title="Node.js">
    ```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
    import { GoogleGenAI } from "@google/genai";

    const client = new GoogleGenAI({
      apiKey: process.env.ORQ_API_KEY,
      httpOptions: {
        baseUrl: "https://my.orq.ai/v3/google",
      },
    });

    const response = await client.models.generateContent({
      model: "gemini-2.5-flash",
      contents: "Explain the repository structure.",
    });

    console.log(response.text);
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    import os

    from google import genai
    from google.genai import types

    client = genai.Client(
        api_key=os.environ["ORQ_API_KEY"],
        http_options=types.HttpOptions(
            base_url="https://my.orq.ai/v3/google",
        ),
    )

    response = client.models.generate_content(
        model="gemini-2.5-flash",
        contents="Explain the repository structure.",
    )

    print(response.text)
    ```
  </Tab>
</Tabs>

Use a bare `gemini-*` model ID or any `provider/model` identifier enabled in the workspace. Find available identifiers in [supported models](/docs/ai-gateway/supported-models).

<Note>
  Gemini models with thinking enabled count thinking tokens toward `maxOutputTokens`. Set `thinkingConfig.thinkingBudget` to `0` to disable thinking on supported models.
</Note>

## Verification

Run a prompt, then open [**Orq.ai** Traces](/docs/ai-studio/observability/traces). Confirm the trace records the selected model and the workspace associated with the API key.
