opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Model in @ai-sdk/openai sdk fails on the 2nd request

Open junmediatek opened this issue 3 weeks ago • 5 comments

Description

When I use @ai-sdk/openai to access openai models which only support Response API(like gpt-5.1-codex), and I set the store to false & "include": ["reasoning.encrypted_content"], the second request fails with below error message

ERROR 2025-12-05T05:28:32 +3ms service=session.processor error=The encrypted content for item rs_0f26baa4a8bfec6b0169326d7c20a8819499e6d836076cc00b could not be verified. stack="AI_APICallError: The encrypted content for item rs_0f26baa4a8bfec6b0169326d7c20a8819499e6d836076cc00b could not be verified.\n at <anonymous> (../../node_modules/.bun/@[email protected]+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:889:18)\n at processTicksAndRejections (native:7:39)" process

The request body has reasoning information with id & encrypted_content item, when the store has been set to false, reasoning should not include id & encrypted_content, because the server does not store the reasoning information. The only content that needs to be included in reasoning should be the summary, provided that the summary exists.

Partial request body information is as follows: {"role":"user","content":[{"type":"input_text","text":"hi"}]},{"type":"reasoning","id":"rs_0f26baa4a8bfec6b0169326d7c20a8819499e6d836076cc00b","encrypted_content":"gAAAAABpMm18nXrFLUlQWklcTxLxRKja9xTgzkc-EOx3-KI7h1DGIDFpIEjdUbaOCnnLjXdxT52UYCnz8C_VAOmdNO-cKgUqDKbYkZlnuGKAYrgZUoLsiYpp-uyWKrnpU5kZdusMxhARLjNdiVBW82Ll-ug_glO3jeqRUuiDDPXKMuL9MleLGzfXg2MtYq952meJDVqFA32gRo-T-nV2UZH2V9BtbBjltAkVo1yWbv5oC4neD4K3t1Tiyo72GmfVR2ZAkzOTpjobSVUTGrsCQzQytpbl6vAbHcIa9-z0Y0Y0lTQ7TZBBJE971-GzsVjhG2cDOrkEUGZlEcEZEbalVe_6tUSw1icClbMGhPCLMm8RDT_IjTvP2x6kdQRlzKYsZLj4KMl_FesRQJdsvqqSg7HJFPJvQbMpoLuMscEhjmIwIcQ0SGEfUsfNo57i02Pl8iPzASD-LYgHjdYG0CrHxRPeWWW3Jm-t9McmSTpC7iyGpK9cdz1nBkjH5HRXofL0RTIOR4pYffDjvjbreRnWakLvpjYEzIYPEUVjNJb9XScFMJJsAnIcNS4p2BmZNHr3JjAbx_1g1-mm7e-VkkoXyrFY3F5MUQokpXtHfMoBHBrYmgtBmBbC7oxxp4WN0WQgtg2C1Re4gyce7TZ92dMYeb9qJLD_hMfHcvKqS_xjiO5Glz5WuhiQ1VeDR9TGAWXf8vA9FXlhLUbW2fRiE4BH1cASRhy1CpBK3Jn0QZ84BDYvmw3MkjeWVLgIgqa80iUHKHQoOIKRtryPK3uYUds_wYn5KnOYwLZO_AiLExgj1cTtdqggdC2oNlcKDcJAm65kFYw2pFj3JpemUu9bld2zN9Lva-PF0zFtVRfd5Td-j7iwDEAJzObiWTBTs627AJWGrbUo4jreqooH","summary":[]},{"role":"assistant","content":[{"type":"output_text","text":"hello, what can I do for you?"}],"id":"msg_0f26baa4a8bfec6b0169326d7c76b881949ca449a294f5d379"},{"role":"user","content":[{"type":"input_text","text":"hello"}]}],"max_output_tokens":32000,"store":false,"include":["reasoning.encrypted_content"],

my opencode.json is below:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "gaisf-openai": {
      "npm": "@ai-sdk/openai",
      "name": "gaisf-openai",
      "options": {
        "baseURL": "https://mlop-gateway-rddmz.xxxx.inc/openai",
        "apiKey": "{env:MY_GAISF_KEY}",
        "timeout": 300000
      },
      "models": {
        "gpt-5.1-codex-medium": {
          "id": "gpt-5.1-codex",
          "name": "gpt-5.1-codex-medium",
          "attachment": true,
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "options": {
            "store": false,
            "include": ["reasoning.encrypted_content"],
            "reasoningEffort": "medium",
            "reasoningSummary": "auto"
          }
        }
      }
    }
  }
}

OpenCode version

1.0.133

Steps to reproduce

Using @ai-sdk/openai sdk to access GPT-5.1 Codex model

Send "Hi" -> Works Send "Hello" next -> Fails

Screenshot and/or share link

NA

Operating System

ubuntu 24.04

Terminal

VSCode remoteSSH Terminal

junmediatek avatar Dec 05 '25 06:12 junmediatek

@rekram1-node

Could you help to check this issue?

junmediatek avatar Dec 05 '25 06:12 junmediatek

This issue might be a duplicate of existing issues. Please check:

  • #4445: Using GPT 5.1 Codex via OpenAI fails on the 2nd request - identical symptom where first request works but second request fails with item not found error
  • #4426: GPT-5.1-codex OpenAI item with id not found error - same root cause with reasoning items when store is false
  • #2941: gpt-5-codex failure with reasoning items - related to reasoning item handling in multi-turn conversations
  • #2966: AI_APICallError with GPT-5-codex in Zero Data Retention organizations - similar issue with store settings and item persistence

All these issues appear to be related to improper handling of reasoning items (with id and encrypted_content) when store: false is set, particularly on subsequent requests in multi-turn conversations.

Feel free to ignore if this is a regression or if your specific setup differs from the above issues.

github-actions[bot] avatar Dec 05 '25 06:12 github-actions[bot]

@junmediatek can you do:

opencode export > session.json

and then send me that?

select the session that errored or make a new one and then gimme json output

rekram1-node avatar Dec 05 '25 06:12 rekram1-node

@rekram1-node

I make a new conversation session.json

junmediatek avatar Dec 05 '25 06:12 junmediatek

Idk how ur gateway works but when u use the responses api you HAVE to go to the same server everytime, whatever happens w/ ur setup its going to different servers and failing to verify the reasoning hash.

rekram1-node avatar Dec 05 '25 06:12 rekram1-node

Idk how ur gateway works but when u use the responses api you HAVE to go to the same server everytime, whatever happens w/ ur setup its going to different servers and failing to verify the reasoning hash.

The root cause of this issue is exactly as you said. Thank you, I have resolve this issue

junmediatek avatar Dec 16 '25 05:12 junmediatek