fix(core): skip stream_options for providers that reject it (Cerebras 422)#32
fix(core): skip stream_options for providers that reject it (Cerebras 422)#32cdxiaodong wants to merge 2 commits intoiOfficeAI:mainfrom
Conversation
… 422) Some OpenAI-compatible providers (e.g. Cerebras) strictly validate request parameters and return HTTP 422 for unknown fields like stream_options. Add shouldIncludeStreamOptions() to conditionally exclude stream_options based on the provider's hostname. Fixes iOfficeAI/AionUi#1038
kuishou68
left a comment
There was a problem hiding this comment.
@cdxiaodong Thanks for the contribution! The code change looks clean and follows the existing pattern (shouldIncludeMetadata()). A few things need to be addressed before we can merge:
Required
-
Add unit tests — Per our project conventions, all OpenAI-related changes need corresponding tests in
openaiContentGenerator.test.ts. Please add tests covering:- Cerebras baseURL (
https://api.cerebras.ai/v1) →stream_optionsshould be omitted - Normal providers (OpenAI, DeepSeek, etc.) →
stream_optionsshould still be included - Invalid/empty URL fallback → should default to including
stream_options
- Cerebras baseURL (
-
Trigger CI — There are no CI checks on this branch yet. Please ensure
npm run build && npm run testpasses.
Optional (nice-to-have)
-
Consider extracting
strictProvidersinto a shared constant or config if we expect more providers to be added over time. Not a blocker for this PR though. -
The
.endsWith('.' + h)subdomain matching forapi.cerebras.aiis unlikely to match in practice, but it's harmless so fine to keep.
Overall the fix is small, safe, and well-scoped. Just need the tests and a green CI run to proceed. 👍


Summary
stream_optionsas an unknown field.shouldIncludeStreamOptions()method that checks the provider's base URL and conditionally omitsstream_optionsfor known strict providers (e.g.api.cerebras.ai).Changes
packages/core/src/core/openaiContentGenerator.ts: AddedshouldIncludeStreamOptions()helper and conditionally spreadstream_optionsin streaming requests.Test plan
npm run test --workspace @office-ai/aioncli-coreOPENAI_BASE_URL=https://api.cerebras.ai/v1) — should no longer get 422stream_optionsshould still be included as before