Skip to content

Client identification for Gemini API #19

@thorwebdev

Description

@thorwebdev

Hey team, would it be possible to add the following client identification to the library to help us track usage origins better?

X-Goog-Api-Client: API client identification. The value is a space-separated list of NAME "/" SEMVER strings, where the NAME should only contain lowercase letters, digits, and "-", and the SEMVER should be a semantic version string. For example: X-Goog-Api-Client: python/3.5.0 grpc-google-pubsub-v1/0.1.0-beta2 linux/2.7.0.

See system parameter docs here: https://docs.cloud.google.com/apis/docs/system-parameters

Example: 
## Python:

from google import genai

client = genai.Client(
    api_key="...",
    http_options={
        "headers": {
            "x-goog-api-client": "my-sdk-py/1.23",
        }
    }
)

## JavaScript
import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({
    apiKey: '...',
    httpOptions: {
        headers: {
            'x-goog-api-client': 'my-sdk-js/1.23'
        }
    }
});

## Direct API
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY \
    -H 'Content-Type: application/json'
    -H 'X-Goog-Api-Client: my-sdk/1.23'
    -d '{...}'

You can see an example implementation of that client identification in the SDK here: https://github.com/google/adk-python/blob/main/src/google/adk/models/google_llm.py#L262-L272

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions