Skip to content

google-genai SDK EmbedContentResponse Discards usageMetadata and Leaves sdk_http_response.body as None #2658

Description

@DylanRussell

EmbedContentResponse type has no usage_metadata field, so it seems that the field is discarded when it's returned from the API.

When instantiating types.HttpResponse, the SDK only passes headers=response.headers and completely omits the body argument.

Reproduction:

import json
import httpx
import google.genai

# Replace with your actual Gemini API key
API_KEY = "YOUR_GEMINI_API_KEY"

# 1. Inspect the SDK Response Object
client = google.genai.Client(api_key=API_KEY)
response = client.models.embed_content(
    model="gemini-embedding-2",
    contents="hello world",
)

print("=== 1. SDK Response Object ===")
print("Response fields:       ", list(response.model_fields.keys()))
print("Response metadata:     ", response.metadata)
print("sdk_http_response.body:", response.sdk_http_response.body)
print()

# 2. Inspect the Raw Wire Response from the Gemini API
print("=== 2. Raw Wire Response from Gemini API ===")
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent?key={API_KEY}"
payload = {
    "model": "models/gemini-embedding-2",
    "content": {"parts": [{"text": "hello world"}]}
}
raw_resp = httpx.post(url, json=payload)
print(json.dumps(raw_resp.json(), indent=2))

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions