Repository navigation
fix(openai): attribute Vercel gateway TypeScript requests - #463
Merged
Merged
Conversation
Keep shared instrumentation, qualify the TypeScript client route, and select matching ESM and CJS declarations. Co-Authored-By: Claude Code <noreply@anthropic.com>
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Keep Vercel AI Gateway on the existing
@traceai/openaiintegration. Correct the receiving-service attribution and provide a version-qualified TypeScript client recipe; do not introduce a duplicate gateway package.clientat the 4.0 floor,_clienton newer SDKs). An exact, normalizedai-gateway.vercel.shhostname recordsgen_ai.provider.name=vercelbefore the request, including failures. Chat Completions, Completions, Responses and Embeddings share the resolver. Other endpoints retain the OpenAI compatibility label; Embeddings now also carry provider attribution.openai@5.23.2, real-SDK/local-OTLP regressions, module type fixtures and focused network-isolated CI. Declare the Zod 3 test dependency already imported by the existing suite. No runtime dependency, version or changelog bump.Reproduction and validation
Base:
d6a9966dd4d5d5fb344f7f5ab11b7483c2c2a6bc(dev). The initial attribution regression using real SDK clients and synthetic fetch responses produced 10 failures / 6 passes on OpenAI 4.0.0 and 13 failures / 6 passes on 5.23.2 and 7.47.0. Gateway spans wereopenai(or missing provider for Embeddings). The unrelated-host controls passed.With outbound networking denied except loopback, the final committed contract passes:
The 7.x row is a manual attribution compatibility probe, not expanded peer or automatic-hook support. The declared 4.x/5.x ranges are unchanged. The floor does not run stream tests because its pre-existing missing
tee()lifecycle issue is handled by the overlapping repair PRs below.Checks include all four instrumented operations where the SDK exposes them, HTTP failures, exact normalized hosts, lookalike hosts, independent/concurrent clients, changed base URLs, malformed/getter-throwing metadata, completed chat streams on 5/7, unchanged returned responses, exactly one client span, reported non-streaming usage, FI project routing, and exclusion of URL/credential markers from the OTLP/HTTP JSON wire. LLM content/error hiding is checked; this does not claim to repair the existing shared-core embedding-content privacy gap.
git diff --checkpassed.TS2345from separate privateAPIError.makeMessagedeclarations. Matching conditional declarations fix it without casts or weakening the public signature. Packed CJS and ESM consumer fixtures typecheck.@traceai/fi-core@1.1.0, OpenAI 5.23.2, synthetic model transport and a localhost collector: one correctly attributed, content-hidden span, expected project/headers and token counts.No vendor/model API, real credential or secret file was used. No live gateway/cloud acceptance or full docs-site browser render is claimed.
Integrate with the existing shared-package repairs
I listed and inspected the open package/page PRs before making changes. #336 does not recognize Vercel's host; #332 is Cloudflare-specific; #410 repairs APIPromise behavior. None fixes this gateway attribution or the qualified ESM type recipe. No existing branch was modified.
The concurrently opened #460 fixes the Python gateway path and is separate from this TypeScript repair; combine their held documentation additions after both packages are released.
These TypeScript PRs touch the same shared instrumentor. When integrating, move the
ai-gateway.vercel.sh -> vercelcase into #336's common host resolver rather than keeping two resolvers; retain #332's explicit Cloudflare policy and #410's lazy promise observer. Do not let a mechanical conflict resolution drop either provider mapping or restore the old stream/promise handling. This PR deliberately does not duplicate those lifecycle repairs or widen the supported SDK range.Documentation and boundaries
The package README ships with the repair. The customer gateway page is staged locally for publication after the corrected package is on npm; no docs PR is opened against an unreleased dependency. The existing Python recipe is retained in that draft.
Vercel Trace Drains expose a separate server-side surface (routing, provider attempts and billing; no prompts/completions). This change does not offer an unvalidated direct-to-Future-AGI drain route. The recipe warns against layering instrumentors or summing client and gateway usage. No package deletion, merge, tag or publication.
Review
Self-reviewed against the internal minimal-code, typing, failure-mode, testing/scenario and PR-review standards. The runtime change is one small host resolver and four call sites; module declaration selection fixes the demonstrated onboarding contract. No application routes, migrations, frontend, tenant authorization or OSS/EE boundary changes. Failure metadata is not logged verbatim because it can contain URL credentials. Human review and reconciliation with the other shared-package repairs are still required.
E2E coverage
Not applicable (no application
e2e/harness). The committed real-SDK/OTLP and packed-declaration contracts are the integration regressions.Sources
traceAI/typescript/packages/traceai_openai/src/instrumentation.ts
Lines 129 to 145 in d6a9966
Generated with Claude Code