Use Proxy with Google Generative AI SDK
https://gateway.adaline.ai/v1/google/
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)
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="")
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 } ) ) )
Was this page helpful?