Google Generative AI SDK Integration

Integrate Proxy with the Google Generative AI SDK to automatically capture telemetry. Demonstrated with Google’s Python SDK but should work in most languages.

Base URL

https://gateway.adaline.ai/v1/google/

Chat Completions

Complete Chat

from google import genai
from google.genai import types

client = genai.Client(
    http_options={
        "base_url": "https://gateway.adaline.ai/v1/google",
        "headers": {
            "adaline-api-key": "your-adaline-api-key",
            "adaline-project-id": "your-project-id",
            "adaline-prompt-id": "your-prompt-id",
        },
    },
    api_key="your-google-api-key",
)

response = client.models.generate_content(
    model="gemini-1.5-pro",
    contents="You are a helpful assistant.\n\nWhat is the future of artificial intelligence?",
    config=types.GenerateContentConfig(
        http_options=types.HttpOptions(
            headers={
                "adaline-trace-name": "google-chat-completion"  # Optional
            }
        )
    )
)

print(response.text)

Stream Chat

from google import genai
from google.genai import types

client = genai.Client(
    http_options={
        "base_url": "https://gateway.adaline.ai/v1/google",
        "headers": {
            "adaline-api-key": "your-adaline-api-key",
            "adaline-project-id": "your-project-id",
            "adaline-prompt-id": "your-prompt-id",
        },
    },
    api_key="your-google-api-key",
)

stream = client.models.generate_content_stream(
    model="gemini-1.5-pro",
    contents="You are a helpful assistant.\n\nExplain the concept of machine learning in detail.",
    config=types.GenerateContentConfig(
        http_options=types.HttpOptions(
            headers={
                "adaline-trace-name": "google-stream-chat"  # Optional
            }
        )
    )
)

for chunk in stream:
    if hasattr(chunk, 'text') and chunk.text:
        print(chunk.text, end="")

Embeddings

from google import genai
from google.genai import types

client = genai.Client(
    http_options={
        "base_url": "https://gateway.adaline.ai/v1/google",
        "headers": {
            "adaline-api-key": "your-adaline-api-key",
            "adaline-project-id": "your-project-id",
            "adaline-prompt-id": "your-prompt-id",
        },
    },
    api_key="your-google-api-key",
)

response = client.models.embed_content(
    model="text-embedding-004",
    contents="The quick brown fox jumps over the lazy dog",
    config=types.EmbedContentConfig(
        http_options=types.HttpOptions(
            headers={
                "adaline-trace-name": "google-embedding"  # Optional
            }
        )
    )
)

Next Steps