Skip to content

fix: report provider model to Langfuse - #317

Open
AlexZahar wants to merge 1 commit into
danny-avila:mainfrom
AlexZahar:codex/langfuse-provider-model
Open

fix: report provider model to Langfuse#317
AlexZahar wants to merge 1 commit into
danny-avila:mainfrom
AlexZahar:codex/langfuse-provider-model

Conversation

@AlexZahar

Copy link
Copy Markdown

Summary

  • prefer the provider-reported response model when exporting Langfuse generations
  • normalize Azure Model Router values such as model-routergpt-5.5-2026-04-24 to the concrete model/version
  • preserve the existing Bedrock usage normalization

Why

Langfuse currently receives the configured alias (model-router) through model_name, while Azure returns the selected model/version in response_metadata.model. The generic alias prevents Langfuse from matching model pricing and leaves generation cost details empty.

Verification

  • focused Langfuse callback suite: 10 tests passed
  • ESLint
  • TypeScript type-check
  • package build

@danny-avila

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0afbfd185f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/langfuse.ts
Comment on lines +151 to +152
responseModel !== message.response_metadata.model_name
? { ...message.response_metadata, model_name: responseModel }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve valid model_name when model metadata is concatenated

For streamed Responses calls where both response.created and response.completed carry model, src/llm/openai/utils/index.ts:983-996 writes both values into response_metadata.model, and src/llm/openai/streamMetadata.ts:3-9 documents that repeated scalar metadata is concatenated. In those runs the final model can be gpt-5gpt-5 (or <deployment>gpt-5-mini for a custom model-router deployment), and these lines replace the correct model_name with that concatenated value, so Langfuse pricing lookup regresses for normal/custom streamed calls rather than only fixing the literal model-router... case.

Useful? React with 👍 / 👎.

Comment thread src/langfuse.ts
const chatGeneration: ChatGeneration = {
...(generation as ChatGeneration),
message: cloneMessageWithUsage(message, usageMetadata),
message: cloneMessageForLangfuse(message, usageMetadata, responseMetadata),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid cloning chunk tool calls away when only the model changes

When this new model-name path handles an AIMessageChunk that already has parsed tool_calls but no actual tool_call_chunks, the clone path passes the chunk's default empty tool_call_chunks array into the AIMessageChunk constructor. That constructor rebuilds tool_calls from the defined chunk list, so model-router/custom streamed tool-call outputs in this shape lose their tool calls before Langfuse extracts the output.

Useful? React with 👍 / 👎.

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.

2 participants