AI_APICallError: Bad Request Open Router #355

Closed
opened 2026-02-16 17:26:25 -05:00 by yindo · 18 comments
Owner

Originally created by @wienans on GitHub (Jun 28, 2025).

Originally assigned to: @thdxr on GitHub.

I configured openrouter as my provider using claude4 and started opencode in a existing project with the /init command.

https://opencode.ai/s/qM8fgbDQ

After searching for the .github/copilot-instructions.md it fails with a AI_APICallError: Bad Request

I tried it multiple times it always goes wrong there.

In one try i even had an error for the checking of .github/copilot-instructions.md something along the lines of EOENT file not found. Sadly i didn't saved it, because my first terminal (standard ubuntu terminal and Terminator) i used didn't copyed the share link to the clipboard and since i removed the sessions.

Originally created by @wienans on GitHub (Jun 28, 2025). Originally assigned to: @thdxr on GitHub. I configured openrouter as my provider using claude4 and started opencode in a existing project with the /init command. https://opencode.ai/s/qM8fgbDQ After searching for the .github/copilot-instructions.md it fails with a AI_APICallError: Bad Request I tried it multiple times it always goes wrong there. In one try i even had an error for the checking of .github/copilot-instructions.md something along the lines of EOENT file not found. Sadly i didn't saved it, because my first terminal (standard ubuntu terminal and Terminator) i used didn't copyed the share link to the clipboard and since i removed the sessions.
yindo closed this issue 2026-02-16 17:26:25 -05:00
Author
Owner

@wienans commented on GitHub (Jun 29, 2025):

https://opencode.ai/s/wMV3nvJ5

Here the mentioned error which wasn't visible in the first share about ENOENT no such file.

Also tried with new version issue is still there, as you can see in the new share link

@wienans commented on GitHub (Jun 29, 2025): https://opencode.ai/s/wMV3nvJ5 Here the mentioned error which wasn't visible in the first share about ENOENT no such file. Also tried with new version issue is still there, as you can see in the new share link
Author
Owner

@DimitriGilbert commented on GitHub (Jun 29, 2025):

https://opencode.ai/s/tHue26U7

Same here. I can provide anything you need if you tell me what.

@DimitriGilbert commented on GitHub (Jun 29, 2025): https://opencode.ai/s/tHue26U7 Same here. I can provide anything you need if you tell me what.
Author
Owner

@rj45 commented on GitHub (Jul 2, 2025):

Same issue, OpenRouter + Claude 4 does not work, can't get it to /init. I ran opencode with --print-logs and here is an excerpt:

INFO  2025-07-02T15:44:05 +383ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +18ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call part
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.part.updated publishing
INFO  2025-07-02T15:44:05 +6ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-streaming-start part
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.part.updated publishing
INFO  2025-07-02T15:44:05 +1ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +3ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-result part
INFO  2025-07-02T15:44:05 +1ms service=bus type=message.part.updated publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing
INFO  2025-07-02T15:44:05 +323ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part
INFO  2025-07-02T15:44:05 +2ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call part
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.part.updated publishing
INFO  2025-07-02T15:44:05 +1ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing
INFO  2025-07-02T15:44:05 +11ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-result part
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.part.updated publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:05 +1ms service=bus type=message.updated publishing
INFO  2025-07-02T15:44:05 +32ms service=session finishReason=tool-calls step finish
INFO  2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=step-finish part
INFO  2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=step-finish unhandled
INFO  2025-07-02T15:44:05 +0ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing
ERROR 2025-07-02T15:44:09 +4048ms service=session error=AI_APICallError: Bad Request stream error
INFO  2025-07-02T15:44:09 +0ms service=bus type=session.error publishing
INFO  2025-07-02T15:44:09 +2ms service=bus type=storage.write publishing
INFO  2025-07-02T15:44:09 +0ms service=bus type=message.updated publishing
INFO  2025-07-02T15:44:09 +0ms service=session sessionID=ses_83430ef4cffextc7K3iYBad865 unlocking
INFO  2025-07-02T15:44:09 +0ms service=bus type=session.idle publishing
INFO  2025-07-02T15:44:09 +1ms service=server duration=15304 response

This is reproducible, and happens every single time. I'd love to try opencode, but my Claude API immediately hits a rate limit error which opencode doesn't seem to recover from, and I can't use openrouter as I get this error. I can use Gemini with openrouter but I would much rather use Claude Sonnet 4.

@rj45 commented on GitHub (Jul 2, 2025): Same issue, OpenRouter + Claude 4 does not work, can't get it to `/init`. I ran opencode with `--print-logs` and here is an excerpt: ``` INFO 2025-07-02T15:44:05 +383ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +18ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call part INFO 2025-07-02T15:44:05 +0ms service=bus type=message.part.updated publishing INFO 2025-07-02T15:44:05 +6ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-streaming-start part INFO 2025-07-02T15:44:05 +0ms service=bus type=message.part.updated publishing INFO 2025-07-02T15:44:05 +1ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +3ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-result part INFO 2025-07-02T15:44:05 +1ms service=bus type=message.part.updated publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing INFO 2025-07-02T15:44:05 +323ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call-delta part INFO 2025-07-02T15:44:05 +2ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-call part INFO 2025-07-02T15:44:05 +0ms service=bus type=message.part.updated publishing INFO 2025-07-02T15:44:05 +1ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing INFO 2025-07-02T15:44:05 +11ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=tool-result part INFO 2025-07-02T15:44:05 +0ms service=bus type=message.part.updated publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:05 +1ms service=bus type=message.updated publishing INFO 2025-07-02T15:44:05 +32ms service=session finishReason=tool-calls step finish INFO 2025-07-02T15:44:05 +1ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=step-finish part INFO 2025-07-02T15:44:05 +0ms service=session session=ses_83430ef4cffextc7K3iYBad865 type=step-finish unhandled INFO 2025-07-02T15:44:05 +0ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:05 +0ms service=bus type=message.updated publishing ERROR 2025-07-02T15:44:09 +4048ms service=session error=AI_APICallError: Bad Request stream error INFO 2025-07-02T15:44:09 +0ms service=bus type=session.error publishing INFO 2025-07-02T15:44:09 +2ms service=bus type=storage.write publishing INFO 2025-07-02T15:44:09 +0ms service=bus type=message.updated publishing INFO 2025-07-02T15:44:09 +0ms service=session sessionID=ses_83430ef4cffextc7K3iYBad865 unlocking INFO 2025-07-02T15:44:09 +0ms service=bus type=session.idle publishing INFO 2025-07-02T15:44:09 +1ms service=server duration=15304 response ``` This is reproducible, and happens every single time. I'd love to try opencode, but my Claude API immediately hits a rate limit error which opencode doesn't seem to recover from, and I can't use openrouter as I get this error. I can use Gemini with openrouter but I would much rather use Claude Sonnet 4.
Author
Owner

@thdxr commented on GitHub (Jul 2, 2025):

i did start seeing this on openrouter yesterday randomly - i wonder if this is an issue on their end because it only popped up yesterday after anthropic downtime

@thdxr commented on GitHub (Jul 2, 2025): i did start seeing this on openrouter yesterday randomly - i wonder if this is an issue on their end because it only popped up yesterday after anthropic downtime
Author
Owner

@thdxr commented on GitHub (Jul 2, 2025):

yeah if i reproduce it and keep trying it works

@thdxr commented on GitHub (Jul 2, 2025): yeah if i reproduce it and keep trying it works
Author
Owner

@wienans commented on GitHub (Jul 2, 2025):

yeah if i reproduce it and keep trying it works

What do you mean with keep trying?

I had issues with sonnet 4 on opencode I switched to roocode to do the task and that didn’t had any issues in the same timespan.

Later I tried to switched to 3.7 sonnet and initially I thought the error was not happening but after 5 to 10 minutes out of nowhere it happened. Then I promted to resume the task and then requests go through again.

Edit:
I retried it with the /init at Issue creation it was always reproducable with that and currently with v0.1.176 it is at least not directly at the start with /init.
I tried to back test with v0.1.157 but your automatic update made it hard so i don't know if it is even using 0.1.157.

@wienans commented on GitHub (Jul 2, 2025): > yeah if i reproduce it and keep trying it works What do you mean with keep trying? I had issues with sonnet 4 on opencode I switched to roocode to do the task and that didn’t had any issues in the same timespan. Later I tried to switched to 3.7 sonnet and initially I thought the error was not happening but after 5 to 10 minutes out of nowhere it happened. Then I promted to resume the task and then requests go through again. Edit: I retried it with the /init at Issue creation it was always reproducable with that and currently with v0.1.176 it is at least not directly at the start with /init. I tried to back test with v0.1.157 but your automatic update made it hard so i don't know if it is even using 0.1.157.
Author
Owner

@thdxr commented on GitHub (Jul 2, 2025):

you can turn off autoupdate in the config

and by keep trying i mean if i tell opencode "try again" it eventually works again

so far it's looking like an openrouter issue

@thdxr commented on GitHub (Jul 2, 2025): you can turn off autoupdate in the config<br><br>and by keep trying i mean if i tell opencode "try again" it eventually works again<br><br>so far it's looking like an openrouter issue
Author
Owner

@Leka74 commented on GitHub (Jul 3, 2025):

Yeah having same issue. I usually just have to tell it "continue" couple of times and it picks up, still a bit annoying since you have to monitor it all the time to see if it needs some encouragement to continue.

@Leka74 commented on GitHub (Jul 3, 2025): Yeah having same issue. I usually just have to tell it "continue" couple of times and it picks up, still a bit annoying since you have to monitor it all the time to see if it needs some encouragement to continue.
Author
Owner

@wienans commented on GitHub (Jul 3, 2025):

Printing continue will also make a different request. If they implement 400 bad request correctly then the issue is likely in the request itself. Would like to debug it further with logging the exact request and retrying that one via curl for example. I assume there is not a logging that specific, would be nice if someone could steer me in the right direction where to look for the request to openrouter in the source code. And where this logging might be good to implement for testing purposes.

I wanted to run the source code version (executed the bun install and then bun run dev) but terminal freezes directly after showing the auth selection. can not use up and down key arrows or Ctrl+c

@wienans commented on GitHub (Jul 3, 2025): Printing continue will also make a different request. If they implement 400 bad request correctly then the issue is likely in the request itself. Would like to debug it further with logging the exact request and retrying that one via curl for example. I assume there is not a logging that specific, would be nice if someone could steer me in the right direction where to look for the request to openrouter in the source code. And where this logging might be good to implement for testing purposes. I wanted to run the source code version (executed the bun install and then bun run dev) but terminal freezes directly after showing the auth selection. can not use up and down key arrows or Ctrl+c
Author
Owner

@seaweeduk commented on GitHub (Jul 3, 2025):

same issue here, after asking it to continue twice it usually carries on but its consuming extra requests

@seaweeduk commented on GitHub (Jul 3, 2025): same issue here, after asking it to continue twice it usually carries on but its consuming extra requests
Author
Owner

@tekn0x commented on GitHub (Sep 11, 2025):

I am having all types of issues with open router models in OpenCode. If a model works it's for a few requests.

@tekn0x commented on GitHub (Sep 11, 2025): I am having all types of issues with open router models in OpenCode. If a model works it's for a few requests.
Author
Owner

@rekram1-node commented on GitHub (Sep 11, 2025):

@tekn0x what kind of errors? And with which models?

@rekram1-node commented on GitHub (Sep 11, 2025): @tekn0x what kind of errors? And with which models?
Author
Owner

@tekn0x commented on GitHub (Sep 12, 2025):

@tekn0x what kind of errors? And with which models?

These are from various free models on brand new sessions. All I said was "Hello"

Kimi K2 (Free)
AI_APICallError: This endpoint's maximum context length is 32768 tokens. However, you requested about 44124
tokens (3868 of text input, 8256 of tool input, 32000 in the output). Please reduce the length of either one,
or use the "middle-out" transform to compress your prompt automatically.

Qwen 3 8B (Free)
AI_APICallError: No endpoints found that support tool use. To learn more about provider routing, visit:
https://openrouter.ai/docs/provider-routing

@tekn0x commented on GitHub (Sep 12, 2025): > [@tekn0x](https://github.com/tekn0x) what kind of errors? And with which models? These are from various free models on brand new sessions. All I said was "Hello" Kimi K2 (Free) AI_APICallError: This endpoint's maximum context length is 32768 tokens. However, you requested about 44124 tokens (3868 of text input, 8256 of tool input, 32000 in the output). Please reduce the length of either one, or use the "middle-out" transform to compress your prompt automatically. Qwen 3 8B (Free) AI_APICallError: No endpoints found that support tool use. To learn more about provider routing, visit: https://openrouter.ai/docs/provider-routing
Author
Owner

@rekram1-node commented on GitHub (Sep 12, 2025):

@tekn0x for Qwen 3 8B (Free) did you add that model yourself? If it doesn't support tools you can put "tool_call": false in the model definition within your config

For the other one we need smarter compacting, etc and there are a variety of issues tracking that. That said, I recommend using models that have a bit bigger context windows the free openrouter models probably aren't going to yield the best results all the time

@rekram1-node commented on GitHub (Sep 12, 2025): @tekn0x for Qwen 3 8B (Free) did you add that model yourself? If it doesn't support tools you can put `"tool_call": false` in the model definition within your config For the other one we need smarter compacting, etc and there are a variety of issues tracking that. That said, I recommend using models that have a bit bigger context windows the free openrouter models probably aren't going to yield the best results all the time
Author
Owner

@tekn0x commented on GitHub (Sep 12, 2025):

@tekn0x for Qwen 3 8B (Free) did you add that model yourself?

Everything was though Open Router. I just selected the models using the /models command and searching for "free"

For the other one we need smarter compacting, etc and there are a variety of issues tracking that. That said, I recommend using models that have a bit bigger context windows the free openrouter models probably aren't going to yield the best results all the time

All I said was "Hello" lol.

@tekn0x commented on GitHub (Sep 12, 2025): > [@tekn0x](https://github.com/tekn0x) for Qwen 3 8B (Free) did you add that model yourself? Everything was though Open Router. I just selected the models using the /models command and searching for "free" > For the other one we need smarter compacting, etc and there are a variety of issues tracking that. That said, I recommend using models that have a bit bigger context windows the free openrouter models probably aren't going to yield the best results all the time All I said was "Hello" lol.
Author
Owner

@rekram1-node commented on GitHub (Sep 12, 2025):

I misread the Kimi k2 free thing actually I think we can fix that one that's a miscount. This one is kinda weird tho because we would need to subtract the input tokens from the output ask before sending request... idk something is weird there

Also I see the qwen/qwen3-8b:free thing now my bad

Okay so both of these are solvable on our end actually sorry about the back and forth

@rekram1-node commented on GitHub (Sep 12, 2025): I misread the Kimi k2 free thing actually I think we can fix that one that's a miscount. This one is kinda weird tho because we would need to subtract the input tokens from the output ask before sending request... idk something is weird there Also I see the `qwen/qwen3-8b:free` thing now my bad Okay so both of these are solvable on our end actually sorry about the back and forth
Author
Owner

@tekn0x commented on GitHub (Sep 12, 2025):

I misread the Kimi k2 free thing actually I think we can fix that one that's a miscount. This one is kinda weird tho because we would need to subtract the input tokens from the output ask before sending request... idk something is weird there

Also I see the qwen/qwen3-8b:free thing now my bad

Okay so both of these are solvable on our end actually sorry about the back and forth

No problem at all. Thank you for the support. I'm happy to help.

@tekn0x commented on GitHub (Sep 12, 2025): > I misread the Kimi k2 free thing actually I think we can fix that one that's a miscount. This one is kinda weird tho because we would need to subtract the input tokens from the output ask before sending request... idk something is weird there > > Also I see the `qwen/qwen3-8b:free` thing now my bad > > Okay so both of these are solvable on our end actually sorry about the back and forth No problem at all. Thank you for the support. I'm happy to help.
Author
Owner

@rekram1-node commented on GitHub (Dec 27, 2025):

[automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!

@rekram1-node commented on GitHub (Dec 27, 2025): [automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#355