fix: report provider model to Langfuse - #317
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 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".
| responseModel !== message.response_metadata.model_name | ||
| ? { ...message.response_metadata, model_name: responseModel } |
There was a problem hiding this comment.
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 👍 / 👎.
| const chatGeneration: ChatGeneration = { | ||
| ...(generation as ChatGeneration), | ||
| message: cloneMessageWithUsage(message, usageMetadata), | ||
| message: cloneMessageForLangfuse(message, usageMetadata, responseMetadata), |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
model-routergpt-5.5-2026-04-24to the concrete model/versionWhy
Langfuse currently receives the configured alias (
model-router) throughmodel_name, while Azure returns the selected model/version inresponse_metadata.model. The generic alias prevents Langfuse from matching model pricing and leaves generation cost details empty.Verification