Repository navigation
fix(server-utils): Derive the Vercel AI conversation id from the OpenAI conversation option #24979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RulaKhaled
merged 5 commits into
develop
from
fix/vercel-ai-conversation-id-from-openai-conversation
Oct 6, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c312063
fix(server-utils): Derive the Vercel AI conversation id from the Open…
RulaKhaled 1206e24
fix(server-utils): Inherit the Vercel AI conversation id only on chil…
RulaKhaled f75342b
Merge branch 'develop' into fix/vercel-ai-conversation-id-from-openai…
RulaKhaled 3bd8e50
Merge remote-tracking branch 'origin/develop' into HEAD
RulaKhaled 216248f
Merge branch 'develop' into fix/vercel-ai-conversation-id-from-openai…
RulaKhaled File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ges/node-integration-tests/suites/tracing/vercelai/v6_v7/scenario-openai-conversation.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { generateText, tool } from 'ai'; | ||
| import { MockLanguageModelV3 } from 'ai/test'; | ||
| import { z } from 'zod'; | ||
|
|
||
| const usage = { | ||
| inputTokens: { total: 10, noCache: 10, cached: 0 }, | ||
| outputTokens: { total: 5, noCache: 5, cached: 0 }, | ||
| totalTokens: { total: 15, noCache: 15, cached: 0 }, | ||
| }; | ||
|
|
||
| const textModel = new MockLanguageModelV3({ | ||
| doGenerate: async () => ({ | ||
| finishReason: { unified: 'stop', raw: 'stop' }, | ||
| usage, | ||
| content: [{ type: 'text', text: 'Hello!' }], | ||
| warnings: [], | ||
| // A per-response id: present on every turn, never the conversation id. | ||
| providerMetadata: { openai: { responseId: 'resp_turn' } }, | ||
| }), | ||
| }); | ||
|
|
||
| const toolCallModel = new MockLanguageModelV3({ | ||
| doGenerate: async () => ({ | ||
| finishReason: { unified: 'tool-calls', raw: 'tool_calls' }, | ||
| usage, | ||
| content: [{ type: 'tool-call', toolCallId: 'tc-1', toolName: 'echo', input: JSON.stringify({ text: 'hi' }) }], | ||
| warnings: [], | ||
| }), | ||
| }); | ||
|
|
||
| async function run() { | ||
| await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { | ||
| // A turn of an OpenAI Conversations API conversation. | ||
| await generateText({ | ||
| experimental_telemetry: { isEnabled: true }, | ||
| model: textModel, | ||
| prompt: 'First turn', | ||
| providerOptions: { openai: { conversation: 'conv_abc123' } }, | ||
| }); | ||
|
|
||
| // The Azure Responses API carries the same option under the `azure` key; this turn also runs a tool. | ||
| await generateText({ | ||
| experimental_telemetry: { isEnabled: true }, | ||
| model: toolCallModel, | ||
| prompt: 'Second turn', | ||
| providerOptions: { azure: { conversation: 'conv_azure' } }, | ||
| tools: { | ||
| echo: tool({ | ||
| inputSchema: z.object({ text: z.string() }), | ||
| execute: async ({ text }) => text, | ||
| }), | ||
| }, | ||
| }); | ||
|
|
||
| // Chaining on the previous response names a response, not a thread, so no conversation id. | ||
| await generateText({ | ||
| experimental_telemetry: { isEnabled: true }, | ||
| model: textModel, | ||
| prompt: 'Chained turn', | ||
| providerOptions: { openai: { previousResponseId: 'resp_turn' } }, | ||
| }); | ||
|
|
||
| // An id set through the SDK API wins over the provider option. Last, since it stays on the scope. | ||
| Sentry.setConversationId('conv-from-api'); | ||
| await generateText({ | ||
| experimental_telemetry: { isEnabled: true }, | ||
| model: textModel, | ||
| prompt: 'API turn', | ||
| providerOptions: { openai: { conversation: 'conv_ignored' } }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| run(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely out of scope for this PR, but I noticed that the direct OpenAI integration does the reverse of this comment:
extractConversationIdinpackages/server-utils/src/ai/openai/utils.tsline 161 mapsprevious_response_idtogen_ai.conversation.id. That has the same problem you're fixing in this PR, because the value differs on each turn of a chain. So the same OpenAI conversation now gets differentgen_ai.conversation.idvalues depending on whether the user calls OpenAI directly or through the AI SDK.I'd suggest naming it in the description here as a todo, and adding a follow-up task to #24832 so we can converge on a single rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yah noticed this, adding it to the description as a todo and will put a task on #24830