Skip to content

Conversation

@EugeneJinXin
Copy link
Contributor

Adds beta TypeScript wrapper for Google Gemini API with automatic LangSmith tracing.

Features

  • Text generation (streaming & non-streaming)
  • Multimodal inputs (text + images)
  • Image generation output (gemini-2.5-flash-image)
  • Function calling
  • Usage metadata extraction
  • compatible format for LangSmith UI rendering (this is beta so it's only a starting point)

@EugeneJinXin EugeneJinXin force-pushed the xin/wrap_gemini_typescript branch 3 times, most recently from eb00750 to 15065e4 Compare November 12, 2025 16:41
Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, some nits and questions

Object.assign(currentRun.extra.metadata.usage_metadata, usageMetadata);

// Fire-and-forget patch to persist changes asynchronously
currentRun.patchRun().catch(() => {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already backgrounded, just await it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually - why do you need this at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the usageMetadata to store in currentRun.extra.metadata.usage_metadata since that's new requirement from the DB team.

openai-api-key:
description: "OpenAI API key"
required: false
gemini-api-key:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this populated in CI? I don't think so?

Let's just omit for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, actually populated already; i added GEMINI_API_KEY in github action

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is used for integration test of gemini wrapper

@EugeneJinXin EugeneJinXin force-pushed the xin/wrap_gemini_typescript branch from bc1edd1 to 11bbdeb Compare November 21, 2025 23:32
.map((chunk) => chunk.text)
.join("");

const result: any = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid any, do you even need this cast?

// Add input token details if available
usageMetadata.input_token_details = {
...(usage.cachedContentTokenCount && {
cache_read_over_200k: Math.max(0, usage.promptTokenCount - 200000),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The math here is a bit trickier I think - cache_read_over_200k and over_200k need to be mutually exclusive for our cost tracking to work out

e.g. if you had a 400k token prompt and 100k were cached the correct usage metadata would be:

{
  input_tokens: 400000,
  input_token_details: {
    cache_read_over_200k: 100000,
    over_200k: 300000,
  }
}

At least that's my read based on: https://ai.google.dev/gemini-api/docs/pricing

We could ask for confirmation there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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.

3 participants