r/opencode • u/Apprehensive-Ad-1333 • 18h ago
Using the opencode API key for Chat Only UI
I have been working on a minimal frontend-only Chat interface for AI (https://github.com/prastavna/aiui).
I was hoping to use the opencode API key for inference. But I am blocked by CORS. Wanted to know if it's possible?
Error:
Access to fetch at 'https://opencode.ai/inference/go/openai/v1/chat/completions' from origin '<redacted> has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
2
Upvotes
1
u/Wise-Bother9942 18h ago
Dude, did you put a Header, like a browser header with your app name etc.
They changed it awhile ago to require full App headers to be sent when using Opencode, if you don't have one it'll just get auto-rejected.
1
u/GhettoFob 8h ago
I think you need to add x-opencode-session
1
u/barbara-j9 1h ago
CORS must be allowed by the endpoint; browser headers won't fix this preflight. If your origin isn't allowed, proxy through a backend and keep the API key there.