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

# Using ElkAPI with Gemini CLI

> Comprehensive guide on configuring ElkAPI API service in Gemini CLI command-line tool. This guide helps you use various AI models through ElkAPI via command line, including Gemini, GPT, and Claude series.

## Introduction

Gemini CLI is Google's official command-line tool that allows developers to interact with Gemini AI models through the terminal. By configuring ElkAPI API, you can use various advanced AI models provided by ElkAPI in Gemini CLI, including GPT, Claude, and Gemini series.

## Prerequisites

Before getting started, ensure you have:

1. **Node.js and npm installed**\
   Download and install from [Node.js official website](https://nodejs.org/) (v16 or higher recommended)

2. **ElkAPI API Key**\
   Log in to [ElkAPI Console](https://api.elkapi.com/keys) to obtain your API key (starts with `sk-`)

<Note>
  **Tip:** If you don't have an ElkAPI account yet, register at [ElkAPI](https://api.elkapi.com) first and obtain an API key.
</Note>

## Step 1: Install Gemini CLI

### 1.1 Global Installation

Install Gemini CLI globally using npm:

```bash theme={null} theme={null}
npm install -g @google/gemini-cli
```

### 1.2 Verify Installation

Check if the installation was successful:

```bash theme={null} theme={null}
gemini --version
```

If it displays a version number, the installation was successful.

## Step 2: Configure ElkAPI API

### 2.1 Temporary Environment Variables

For testing or one-time use, expires when terminal is closed:

**Windows (PowerShell):**

```powershell theme={null} theme={null}
$env:GEMINI_API_KEY = "sk-xxxxxxxxxxxx"
$env:GEMINI_BASE_URL = "https://api.elkapi.com/v1"
```

**macOS/Linux (Bash):**

```bash theme={null} theme={null}
export GEMINI_API_KEY="sk-xxxxxxxxxxxx"
export GEMINI_BASE_URL="https://api.elkapi.com/v1"
```

### 2.2 Permanent Environment Variables (Recommended)

Write configuration to system, automatically applies on every terminal session:

**Windows (PowerShell):**

1. Run PowerShell as Administrator
2. Execute the following commands to set user-level environment variables:

```powershell theme={null} theme={null}
[System.Environment]::SetEnvironmentVariable('GEMINI_API_KEY', 'sk-xxxxxxxxxxxx', 'User')
[System.Environment]::SetEnvironmentVariable('GEMINI_BASE_URL', 'https://api.elkapi.com/v1', 'User')
```

3. Restart PowerShell or execute the following commands to refresh environment variables:

```powershell theme={null} theme={null}
$env:GEMINI_API_KEY = [System.Environment]::GetEnvironmentVariable('GEMINI_API_KEY', 'User')
$env:GEMINI_BASE_URL = [System.Environment]::GetEnvironmentVariable('GEMINI_BASE_URL', 'User')
```

**macOS/Linux (Bash):**

1. Edit the configuration file (choose based on your shell):

```bash theme={null} theme={null}
# For Bash
nano ~/.bashrc

# For Zsh (macOS default)
nano ~/.zshrc
```

2. Add the following at the end of the file:

```bash theme={null} theme={null}
# ElkAPI Gemini CLI Configuration
export GEMINI_API_KEY="sk-xxxxxxxxxxxx"
export GEMINI_BASE_URL="https://api.elkapi.com/v1"
```

3. Save the file and reload configuration:

```bash theme={null} theme={null}
# For Bash
source ~/.bashrc

# For Zsh
source ~/.zshrc
```

### 2.3 Using .env File

Create a `.env` file in your project directory:

```bash theme={null} theme={null}
# .env
GEMINI_API_KEY=sk-xxxxxxxxxxxx
GEMINI_BASE_URL=https://api.elkapi.com/v1
```

Then load environment variables before running commands:

**macOS/Linux:**

```bash theme={null} theme={null}
export $(cat .env | xargs) && gemini chat
```

**Windows (PowerShell):**

```powershell theme={null} theme={null}
Get-Content .env | ForEach-Object {
    $name, $value = $_.split('=')
    Set-Content env:\$name $value
}
gemini chat
```

<Note>
  **Important:**

  * Replace `sk-xxxxxxxxxxxx` with your actual API key from [ElkAPI Console](https://api.elkapi.com/keys)
  * Set `GEMINI_BASE_URL` to `https://api.elkapi.com/v1` to ensure Gemini CLI connects to ElkAPI
  * If using `.env` file, add it to `.gitignore` to avoid exposing your API key
</Note>

### 2.4 Verify Configuration

Check if environment variables are set correctly:

**macOS/Linux:**

```bash theme={null} theme={null}
echo $GEMINI_API_KEY
echo $GEMINI_BASE_URL
```

**Windows (PowerShell):**

```powershell theme={null} theme={null}
echo $env:GEMINI_API_KEY
echo $env:GEMINI_BASE_URL
```

If the correct values are displayed, the configuration is successful.

## Step 3: Start Using Gemini CLI

### 3.1 Basic Conversation

Start interactive conversation:

```bash theme={null} theme={null}
gemini chat
```

Or send a one-time request:

```bash theme={null} theme={null}
gemini "Please explain the history of artificial intelligence"
```

### 3.2 Specify Model

Chat with a specific model:

```bash theme={null} theme={null}
gemini chat --model gpt-5.5
```

Or:

```bash theme={null} theme={null}
gemini "Write a Python quicksort algorithm" --model claude-sonnet-4-6
```

## Step 4: Using ElkAPI API with Code

### 2.1 Using Python SDK

```python theme={null} theme={null}
import openai

# Configure ElkAPI API
openai.api_key = "sk-xxxxxxxxxxxx"  # Your ElkAPI API key
openai.api_base = "https://api.elkapi.com/v1"

# Use Gemini model
response = openai.ChatCompletion.create(
    model="gemini-3.1-flash-lite-preview",
    messages=[
        {"role": "user", "content": "Hello, please introduce yourself"}
    ]
)

print(response.choices[0].message.content)
```

### 2.2 Using JavaScript/TypeScript

```javascript theme={null} theme={null}
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'sk-xxxxxxxxxxxx', // Your ElkAPI API key
  baseURL: 'https://api.elkapi.com/v1'
});

async function main() {
  const completion = await client.chat.completions.create({
    model: 'gemini-3.1-flash-lite-preview',
    messages: [
      { role: 'user', content: 'Hello, please introduce yourself' }
    ]
  });
  
  console.log(completion.choices[0].message.content);
}

main();
```

### 2.3 Using cURL

```bash theme={null} theme={null}
curl https://api.elkapi.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxxxx" \
  -d '{
    "model": "gemini-3.1-flash-lite-preview",
    "messages": [
      {"role": "user", "content": "Hello, please introduce yourself"}
    ]
  }'
```

## Step 3: Choose the Right Model

### Recommended Models

**Gemini Series:**

| Model Name            | Model ID                        | Features                | Use Cases                               |
| --------------------- | ------------------------------- | ----------------------- | --------------------------------------- |
| Gemini 3.1 Flash Lite | `gemini-3.1-flash-lite-preview` | Lightweight, economical | Fast simple tasks                       |
| Gemini 3.1 Pro        | `gemini-3.1-pro-preview`        | Powerful performance    | Complex tasks, professional analysis    |
| Gemini 3.1 Flash Lite | `gemini-3.1-flash-lite-preview` | High-speed response     | Real-time interaction, batch processing |

**GPT Series:**

| Model Name   | Model ID       | Features             | Use Cases                              |
| ------------ | -------------- | -------------------- | -------------------------------------- |
| GPT-5        | `gpt-5.5`      | Latest and strongest | Complex reasoning, creative writing    |
| GPT-5.5      | `gpt-5.5`      | High quality         | Daily conversation, content generation |
| GPT-5.4 Mini | `gpt-5.4-mini` | Cost-effective       | Simple tasks, high-frequency use       |

**Claude Series:**

| Model Name        | Model ID            | Features         | Use Cases                         |
| ----------------- | ------------------- | ---------------- | --------------------------------- |
| Claude Sonnet 4.6 | `claude-sonnet-4-6` | Strong reasoning | Code generation, logical analysis |
| Claude Opus 4.7   | `claude-sonnet-4-6` | Extremely fast   | Quick Q\&A, real-time chat        |

<Tip>
  **Model Selection Tips:**

  * 🚀 **Google Ecosystem:** `gemini-3.1-flash-lite-preview`, `gemini-3.1-pro-preview`
  * 💡 **Code Development:** `claude-sonnet-4-6`, `gpt-5.5`
  * 💰 **Cost Optimization:** `gpt-5.4-mini`, `claude-sonnet-4-6`
  * ⚡ **Fast Response:** `gemini-3.1-flash-lite-preview`, `gpt-5.4-mini`
</Tip>

## Advanced Features

### Multimodal Support

```python theme={null} theme={null}
response = openai.ChatCompletion.create(
    model="gemini-3.1-flash-lite-preview",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What's in this image?"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/image.jpg"
                    }
                }
            ]
        }
    ]
)
```

### Streaming Output

```python theme={null} theme={null}
stream = openai.ChatCompletion.create(
    model="gemini-3.1-flash-lite-preview",
    messages=[{"role": "user", "content": "Write a poem about spring"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end='')
```

## FAQ

### Q1: How to verify API configuration?

```python theme={null} theme={null}
import openai

openai.api_key = "sk-xxxxxxxxxxxx"
openai.api_base = "https://api.elkapi.com/v1"

try:
    response = openai.ChatCompletion.create(
        model="gemini-3.1-flash-lite-preview",
        messages=[{"role": "user", "content": "test"}],
        max_tokens=10
    )
    print("✅ API configuration successful!")
    print(f"Response: {response.choices[0].message.content}")
except Exception as e:
    print(f"❌ API configuration failed: {e}")
```

### Q2: Supported Programming Languages?

ElkAPI API supports all programming languages that can send HTTP requests:

* ✅ **Python** - Recommended with OpenAI SDK
* ✅ **JavaScript/TypeScript** - Node.js and browser
* ✅ **Java** - HTTP client
* ✅ **Go** - Standard library or third-party packages
* ✅ **PHP** - cURL or Guzzle
* ✅ **Ruby** - HTTP library
* ✅ **C#/.NET** - HttpClient
* ✅ **Swift** - URLSession
* ✅ **Other languages** - Any language supporting HTTP

## Features

Using Google AI Studio + ElkAPI, you can:

* 🤖 **Multi-model Support** - Access GPT, Claude, Gemini, and more
* 🌍 **OpenAI Compatible** - Standard OpenAI API format
* ⚡ **High Performance** - Low latency, high concurrency
* 💰 **Transparent Pricing** - Clear pay-as-you-go pricing
* 📊 **Usage Monitoring** - Real-time API call tracking
* 🔒 **Secure & Reliable** - Enterprise-grade security
* 🚀 **Quick Integration** - Simple API calls
* 📚 **Complete Documentation** - Detailed development docs and examples

## Support & Help

If you encounter any issues:

* 📚 [ElkAPI Documentation](https://docs.elkapi.com)
* 📚 [Google AI Studio Documentation](https://ai.google.dev/docs)
* 📧 Technical Support: [support@elkapi.com](mailto:support@elkapi.com)

***

<Card title="Get Started with ElkAPI" icon="rocket" href="https://api.elkapi.com">
  Sign up for ElkAPI now, get your API key, and use multiple AI models in Google AI Studio!
</Card>
