Skip to content

[sdk] tag API requests with the detected AI agent - #320

Merged
erulkey merged 8 commits into
mainfrom
elisabeth/sdk-agent-stamp
Sep 14, 2026
Merged

erulkey merged 8 commits into
mainfrom
elisabeth/sdk-agent-stamp

Conversation

@erulkey

@erulkey erulkey commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #319, which added the agent/<name> user-agent phrase to the CLI. This extends the same stamp to the SDK, so programmatic callers get attributed too once the server side records the header (same ingestion ask, no new dependency on it).

This:

  • appends agent/<name> to the SDK's existing user-agent when detect-agent identifies an AI agent driving the process; no agent means the header is byte-identical to today
  • adds the dedupe guard in the CLI's fetch wrapper so CLI-over-SDK traffic carries exactly one agent phrase, with a unit test pinning that
  • adds detect-agent@1.2.0 as an SDK runtime dependency (zero transitive dependencies, node >=20 which the SDK already requires)

Deliberately not added: telemetry events. The SDK ships in customer production code; this is request metadata only, nothing is collected or sent anywhere new.

Verified:

  • probe with a logging fetch inside a Claude Code session:
UA: vercel/sandbox/3.2.0 agent/claude-code_2-1-247_agent (Node.js/v26.7.0; darwin/arm64)
  • same probe with env -u CLAUDECODE -u CLAUDE_CODE -u AI_AGENT (a deployed server's environment): vercel/sandbox/3.2.0 (Node.js/v26.7.0; darwin/arm64), unchanged
  • combined path unit test asserts exactly one agent/ occurrence in the final header
  • pnpm turbo typecheck --filter=@vercel/sandbox --filter=sandbox --force: 4/4; CLI suite 101 passed; SDK suite 291 passed, 80 skipped (pre-existing live-credential skips)

Detection only labels the process driving the SDK, so servers creating sandboxes to run agents inside them correctly carry no label; that population is the planned self-declared tag, not this PR.

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sandbox Ready Ready Preview, v0 Sep 11, 2026 8:00pm UTC
sandbox-sdk-ai-example Ready Ready Preview, v0 Sep 11, 2026 8:00pm UTC
workflow-code-runner Ready Ready Preview, v0 Sep 11, 2026 8:00pm UTC

@alexfarnhambrown alexfarnhambrown 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.

Checked where this header could land: no sandbox table in PRODUCT has a user_agent column — not the usage facts, not any sandbox event-streaming topic. So both this and #319 depend on an ingestion change that doesn't have a ticket or owner yet. If the landing place is the sandbox usage-fact pipeline, that's the same pipeline we need a failure status from, so it's probably one ask rather than two.

The upside is real though: the composed header separates CLI-driven from programmatic from agent-driven with no join required, which is a split we can't currently make.

Comment thread packages/vercel-sandbox/package.json Outdated
Comment thread packages/vercel-sandbox/src/api-client/api-client.ts
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

You must have Developer access to commit code to Vercel Labs on Vercel. If you contact an administrator and receive Developer access, commit again to see your changes.

Learn more: https://vercel.com/docs/accounts/team-members-and-roles/access-roles#team-level-roles

Comment thread packages/sandbox/src/client.ts Outdated
@erulkey
erulkey marked this pull request as ready for review September 9, 2026 20:32
@erulkey
erulkey requested a review from marc-vercel September 9, 2026 21:13
Comment thread packages/vercel-sandbox/src/utils/detect-agent.ts
Comment thread packages/vercel-sandbox/src/api-client/api-client.ts

@marc-vercel marc-vercel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Left a comment.

Base automatically changed from elisabeth/cli-telemetry to main September 11, 2026 15:02
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Your Vercel team Curated Tests - Permanent E2E is not permitted to deploy from this git repository. Contact an administrator to add github organization vercel as a Protected Git Scope in Curated Tests - Permanent E2E on Vercel. Once added, commit again to see your changes.

Learn more: https://vercel.com/docs/security/protected-git-scopes

@erulkey
erulkey merged commit 9d0403d into main Sep 14, 2026
25 of 28 checks passed
@erulkey
erulkey deleted the elisabeth/sdk-agent-stamp branch September 14, 2026 18:29
@github-actions github-actions Bot mentioned this pull request Sep 14, 2026
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.

4 participants