Skip to content

feat(genai,vertexai): expose provider response ids#1772

Open
Ayush Srivastava (luigivendetta) wants to merge 6 commits into
langchain-ai:mainfrom
luigivendetta:luigivendetta/provider-response-id-metadata
Open

feat(genai,vertexai): expose provider response ids#1772
Ayush Srivastava (luigivendetta) wants to merge 6 commits into
langchain-ai:mainfrom
luigivendetta:luigivendetta/provider-response-id-metadata

Conversation

@luigivendetta

@luigivendetta Ayush Srivastava (luigivendetta) commented May 17, 2026

Copy link
Copy Markdown

Description

Expose Google's provider response identifier as AIMessage.response_metadata["id"] for both langchain-google-genai and langchain-google-vertexai.

This lets users correlate LangChain responses with Gemini and Vertex dashboards/logs without storing prompt or response text. The metadata key matches langchain-openai, which already exposes the native provider response ID through response_metadata["id"].

This intentionally stores the provider ID in response_metadata, not message.id, so it remains additive and does not change LangChain message identity behavior.

Relevant issues

N/A

Type

🆕 New Feature
✅ Test

Changes

  • Add GenAI non-stream response ID metadata from GenerateContentResponse.response_id.
  • Add GenAI streaming response ID metadata on the final chunk only.
  • Add Vertex response ID metadata for non-streaming responses.
  • Add Vertex fallback extraction for raw response shapes that expose response_id / responseId.
  • Add Vertex streaming response ID metadata on the final chunk only.
  • Preserve existing message.id, additional_kwargs, content parsing, thinking blocks, tool-call IDs, and usage metadata behavior.

Why this approach

  • Uses response_metadata["id"] for provider parity with langchain-openai.
  • Keeps the change backward compatible by only adding metadata when the provider returns an ID.
  • Attaches streaming IDs only to the final chunk so concatenated streamed messages contain the ID once.
  • Keeps GenAI and Vertex behavior consistent across Google chat integrations.

Review notes

Areas worth extra review:

  • Whether response_metadata["id"] is the preferred cross-provider key.
  • Whether keeping the ID only on the final streaming chunk is the right merge behavior.
  • Whether the Vertex fallback extraction covers the expected response shapes without being too broad.

Testing

Passed locally:

  • cd libs/genai && UV_CACHE_DIR=/tmp/uv-cache uv lock --check
  • cd libs/genai && UV_CACHE_DIR=/tmp/uv-cache make lint_package
  • cd libs/genai && UV_CACHE_DIR=/tmp/uv-cache make lint_tests
  • cd libs/genai && UV_CACHE_DIR=/tmp/uv-cache make test TEST_FILE=tests/unit_tests/test_chat_models.py
    • 217 passed
  • cd libs/genai && UV_CACHE_DIR=/tmp/uv-cache uv run --group test --group test_integration pytest -m compile tests/integration_tests
  • cd libs/vertexai && UV_CACHE_DIR=/tmp/uv-cache uv lock --check
  • cd libs/vertexai && UV_CACHE_DIR=/tmp/uv-cache make lint_package
  • cd libs/vertexai && UV_CACHE_DIR=/tmp/uv-cache make lint_tests
  • cd libs/vertexai && UV_CACHE_DIR=/tmp/uv-cache make test TEST_FILE=tests/unit_tests/test_chat_models.py
    • 110 passed, 1 skipped
  • cd libs/vertexai && UV_CACHE_DIR=/tmp/uv-cache uv run --group test --group test_integration pytest -m compile tests/integration_tests

Note

This touches both GenAI and Vertex intentionally so provider response ID metadata lands consistently across Google chat integrations. I can split this into separate package PRs if that is easier to review.

This contribution was prepared with assistance from AI agents. The author reviewed and validated the changes locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant