Grouping requests into conversations using an API gateway

Feature request for product/service

Cursor IDE

Describe the request

When Cursor sends POST /v1/chat/completions to a user-configured OpenAI-compatible base URL, include stable identity headers on every request:

  • x-cursor-conversation-id
    • The chat/conversation id (same id hooks already report as conversation_id)
  • x-cursor-agent-id
    • The agent that issued this request (subagent id for Task runs)
  • x-cursor-parent-agent-id
    • The spawning agent, when nested

This is the shape Claude Code’s LLM gateway protocol has and is close to what Codex (thread-id, x-codex-parent-thread-id) and OpenCode (x-session-affinity, x-parent-session-id) do.

Opt-in via a setting is fine. Only sending it to custom base URLs (not Cursor’s own backend) is fine. Sending it all the time is fine.

Why
We run a gateway in front of model traffic and want per-conversation analytics. Other gateway products like LiteLLM and PortKey definitely suffer from this same problem.

With a conversation id (and other things) on the wire we can trivially answer things that are currently out of reach:

  • How latency, TTFT, and cost scale as a conversation’s context grows turn over turn.
  • The real cost/latency impact of compaction events and manual context engineering
  • Cache-hit behavior across a conversation
  • Subagent fan-out: how much of a session’s spend and wall-clock is parent vs. Task children.
    Every one of these is a join across requests.

Without an id, we have an array of anonymous completions that can probably be coalesced with some fancy and (maybe) expensive postprocessing, but it would be wicked nice to have this just be way easier.

What I tried
I built correlation without using hooks (beforeSubmitPrompt, afterAgentResponse, afterAgentThought, preToolUse) that call our gateway out-of-band, plus content fingerprinting - normalize and SHA-256 the prompt (or assistant output) on both sides and join the hook event to the inflight request after the fact. It works for single conversations but is very inconsistent with plan->build handoffs and subagents.

If headers aren’t feasible, a body field (metadata.cursorConversationId or equivalent) would solve most of this too.

Ref: Gateway protocol reference - Claude Code Docs

Related bug that got in my way: `subagentStop` never fires for background subagents; documented `summary` / `modified_files` / `agent_transcript_path` missing or null

Would love an intentional feature for this or advice from someone on how to do this with current tools.

Operating System (if it applies)

MacOS

Cursor does not currently send conversation or agent identity headers (or equivalent metadata) on requests to a custom OpenAI-compatible base URL. Outbound calls to that override path effectively only carry the provider auth you’d expect, so a gateway sees anonymous completions and has to reassemble sessions after the fact - exactly the pain you’re describing.

Hooks can expose conversation_id (and related lifecycle events) for out-of-band correlation, which matches what you already tried. That path is still incomplete for nested / background Task runs; the gaps you hit line up with what’s discussed in subagentStop never fires for background subagents…. Docs for the hook surface: Hooks. For how BYOK / custom keys are routed today: Bring your own API key.

Appreciate the response - do you have any idea if functionality in this realm is in the works?

No timeline to share yet. We’ve let the team know and this is something we’re tracking. I’ll post here when there’s an update.