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

# Gemini

> Integrate HasteKit LLM Gateway with Google Gemini SDKs using the GenerateContent API

HasteKit LLM Gateway supports Google Gemini's **GenerateContent API** for text generation, images, tool calling, and reasoning. You can use **any Gemini SDK** by simply pointing it to HasteKit's gateway endpoint. This allows you to leverage HasteKit's features like virtual keys, provider management, and observability while using your existing Gemini code.

## Overview

The HasteKit LLM Gateway provides an endpoint at `/api/gateway/gemini/v1beta/models/{model}` that implements Google Gemini's GenerateContent API specification. This means you can use any Gemini SDK (Python, JavaScript, Go, etc.) without modifying your code - just change the base URL.

## Usage Examples

<CodeGroup dropdown>
  ```python main.py theme={null}
  import google.generativeai as genai

  # Configure to use HasteKit's gateway endpoint
  genai.configure(
      api_key="sk-hk-your-virtual-key-here",  # or your Gemini API key
      client_options={
          "api_endpoint": "http://localhost:6060/api/gateway/gemini/v1beta"
      }
  )

  # Use the GenerateContent API
  # Note: Model name includes the action (generateContent)
  model = genai.GenerativeModel('gemini-1.5-pro:generateContent')

  response = model.generate_content("Hello, how are you?")
  print(response.text)
  ```

  ```javascript main.js theme={null}
  const { GoogleGenerativeAI } = require('@google/generative-ai');

  const genAI = new GoogleGenerativeAI('sk-hk-your-virtual-key-here'); // or your Gemini API key

  // Configure to use HasteKit's gateway endpoint
  const model = genAI.getGenerativeModel({
    model: 'gemini-1.5-pro:generateContent',
    apiEndpoint: 'http://localhost:6060/api/gateway/gemini/v1beta',
  });

  async function main() {
    const result = await model.generateContent('Hello, how are you?');
    const response = await result.response;
    console.log(response.text());
  }

  main();
  ```

  ```go main.go theme={null}
  package main

  import (
      "context"
      "fmt"

      "google.golang.org/api/option"
      "github.com/google/generative-ai-go/genai"
  )

  func main() {
      ctx := context.Background()
      
      // Configure to use HasteKit's gateway endpoint
      // Note: You'll need to set up a custom HTTP client with the base URL
      // This is a simplified example - you may need to adjust based on the SDK version
      client, err := genai.NewClient(ctx, 
          option.WithAPIKey("sk-hk-your-virtual-key-here"), // or your Gemini API key
          option.WithEndpoint("http://localhost:6060/api/gateway/gemini/v1beta"),
      )
      if err != nil {
          panic(err)
      }
      defer client.Close()

      model := client.GenerativeModel("gemini-1.5-pro:generateContent")
      resp, err := model.GenerateContent(ctx, genai.Text("Hello, how are you?"))
      if err != nil {
          panic(err)
      }

      fmt.Println(resp.Candidates[0].Content.Parts[0].(genai.Text))
  }
  ```
</CodeGroup>

## Streaming Support

The gateway supports streaming responses. Use `streamGenerateContent` as the action in the model name:

<CodeGroup dropdown>
  ```python streaming.py theme={null}
  import google.generativeai as genai

  genai.configure(
      api_key="sk-hk-your-virtual-key-here",
      client_options={
          "api_endpoint": "http://localhost:6060/api/gateway/gemini/v1beta"
      }
  )

  # Use streamGenerateContent as the action
  model = genai.GenerativeModel('gemini-1.5-pro:streamGenerateContent')

  response = model.generate_content("Tell me a story.", stream=True)

  for chunk in response:
      print(chunk.text, end="", flush=True)
  ```

  ```javascript streaming.js theme={null}
  const { GoogleGenerativeAI } = require('@google/generative-ai');

  const genAI = new GoogleGenerativeAI('sk-hk-your-virtual-key-here');

  const model = genAI.getGenerativeModel({
    model: 'gemini-1.5-pro:streamGenerateContent',
    apiEndpoint: 'http://localhost:6060/api/gateway/gemini/v1beta',
  });

  async function main() {
    const result = await model.generateContentStream('Tell me a story.');
    
    for await (const chunk of result.stream) {
      const chunkText = chunk.text();
      if (chunkText) {
        process.stdout.write(chunkText);
      }
    }
  }

  main();
  ```

  ```go streaming.go theme={null}
  package main

  import (
      "context"
      "fmt"

      "google.golang.org/api/option"
      "github.com/google/generative-ai-go/genai"
  )

  func main() {
      ctx := context.Background()
      
      client, err := genai.NewClient(ctx,
          option.WithAPIKey("sk-hk-your-virtual-key-here"),
          option.WithEndpoint("http://localhost:6060/api/gateway/gemini/v1beta"),
      )
      if err != nil {
          panic(err)
      }
      defer client.Close()

      model := client.GenerativeModel("gemini-1.5-pro:streamGenerateContent")
      iter := model.GenerateContentStream(ctx, genai.Text("Tell me a story."))
      
      for {
          resp, err := iter.Next()
          if err != nil {
              break
          }
          if len(resp.Candidates) > 0 && len(resp.Candidates[0].Content.Parts) > 0 {
              if text, ok := resp.Candidates[0].Content.Parts[0].(genai.Text); ok {
                  fmt.Print(string(text))
              }
          }
      }
  }
  ```
</CodeGroup>

## Supported Features

The gateway currently supports the GenerateContent API with:

* ✅ **Text generation** - Standard text completions
* ✅ **Images** - Image input and generation
* ✅ **Tool calling** - Function calling capabilities
* ✅ **Reasoning** - Advanced reasoning models

## Authentication

The gateway accepts authentication via the `key` query parameter:

* **Virtual Key**: Use a virtual key (starts with `sk-hk-`) for managed access control
* **Direct API Key**: Use your Google Gemini API key directly
