Skip to content

feat: chain Responses API response IDs#37507

Open
joaomj wants to merge 1 commit into
anomalyco:devfrom
joaomj:feat/previous-response-id
Open

feat: chain Responses API response IDs#37507
joaomj wants to merge 1 commit into
anomalyco:devfrom
joaomj:feat/previous-response-id

Conversation

@joaomj

@joaomj joaomj commented Jul 17, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #34133

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The Responses API returns a response ID that can be used on the next provider turn as previous_response_id. OpenCode was capturing that metadata but always serializing the full conversation again.

This change carries the response ID through the prompt loop and provider request options. Once a Responses API response ID is available, only the newest message is sent on the next continuation turn. The chain is reset after compaction and whenever processing does not continue. Other providers keep their existing behavior.

How did you verify your code works?

  • Ran bun test test/provider/transform.test.ts in packages/opencode: 348 tests passed.
  • Ran bun x tsgo --noEmit in packages/opencode: passed.
  • The repository pre-push typecheck is currently blocked by an unrelated existing packages/ui error involving missing exports from motion.

Screenshots / recordings

Not applicable, this is a backend/session runtime change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jul 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Tuxie

Tuxie commented Jul 17, 2026

Copy link
Copy Markdown

I hope that isResponsesApiModel() doesn't prevent previousResponseId from being set when using GPT 5.6 via a personal LiteLLM or similar proxy, or for other models that benefit from previous_response_id, such as Grok 4.5 and Muse Spark 1.1

@joaomj

joaomj commented Jul 17, 2026

Copy link
Copy Markdown
Author

I hope that isResponsesApiModel() doesn't prevent previousResponseId from being set when using GPT 5.6 via a personal LiteLLM or similar proxy, or for other models that benefit from previous_response_id, such as Grok 4.5 and Muse Spark 1.1

yes... LiteLLM works when configured with @ai-sdk/openai, but the default @ai-sdk/openai-compatible path is not currently chained. There is also an xAI allowlist mismatch: it receives previousResponseId without switching to delta-only messages. I’ll align these checks and add coverage before merge.

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.

[FEATURE]: support previous_response_id chaining for the OpenAI Responses API path to reduce per-turn token cost in long agentic sessions

2 participants