Skip to content

[BUG] InlinedResponse missing metadata field - batch API responses don't include request metadata #1886

@imohitkr

Description

@imohitkr

Summary

InlinedResponse is missing the metadata field that is documented in the REST API and present in InlinedRequest. This prevents users from tracking custom identifiers through batch processing. The metadata is accepted when submitting requests but cannot be retrieved from responses.

Environment details

  • Programming language: Python
  • OS: macOS (also reproducible on Linux)
  • Language runtime version: Python 3.12.9
  • Package version: google-genai 1.56.0

Steps to reproduce

  1. Create a batch job with metadata attached to inline requests:
from google import genai

client = genai.Client(api_key="...")

inline_requests = [
    {
        "contents": [{"parts": [{"text": "Hello"}], "role": "user"}],
        "config": {"temperature": 0.5},
        "metadata": {"request_id": "req-001", "batch_idx": "0"}
    }
]

batch_job = client.batches.create(model="gemini-2.0-flash", src=inline_requests)
  1. Wait for batch to complete, then retrieve results:
batch_job = client.batches.get(name=batch_job.name)

for resp in batch_job.dest.inlined_responses:
    print(resp.metadata)  # AttributeError: 'InlinedResponse' object has no attribute 'metadata'
  1. Expected: resp.metadata returns {"request_id": "req-001", "batch_idx": "0"}

  2. Actual: AttributeError - the metadata field is not defined on InlinedResponse

Additional context

The REST API documentation shows InlinedResponse should include a metadata field:

{
  "metadata": { object },
  "response": { object (GenerateContentResponse) },
  "error": { object (Status) }
}

However, InlinedResponse in types.py only defines response and error. Additionally, _InlinedResponse_from_mldev in batches.py doesn't copy the metadata field from the raw API response.

Note: InlinedRequest correctly includes the metadata field - it's only missing from InlinedResponse.

Metadata

Metadata

Assignees

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

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions