Skip to content

fix(core): skip stream_options for providers that reject it (Cerebras 422)#32

Open
cdxiaodong wants to merge 2 commits intoiOfficeAI:mainfrom
cdxiaodong:fix/cerebras-422-stream-options
Open

fix(core): skip stream_options for providers that reject it (Cerebras 422)#32
cdxiaodong wants to merge 2 commits intoiOfficeAI:mainfrom
cdxiaodong:fix/cerebras-422-stream-options

Conversation

@cdxiaodong
Copy link

Summary

  • Fixes HTTP 422 errors when using Cerebras as an OpenAI-compatible provider. Cerebras strictly validates request parameters and rejects stream_options as an unknown field.
  • Adds a shouldIncludeStreamOptions() method that checks the provider's base URL and conditionally omits stream_options for known strict providers (e.g. api.cerebras.ai).
  • The fix follows the same pattern used by existing vendor-specific workarounds (DeepSeek, OpenRouter, DashScope).

Changes

  • packages/core/src/core/openaiContentGenerator.ts: Added shouldIncludeStreamOptions() helper and conditionally spread stream_options in streaming requests.

Test plan

  • Verify existing tests pass: npm run test --workspace @office-ai/aioncli-core
  • Test streaming with Cerebras provider (OPENAI_BASE_URL=https://api.cerebras.ai/v1) — should no longer get 422
  • Test streaming with OpenAI/DeepSeek/other providers — stream_options should still be included as before

… 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
Copy link
Collaborator

@kuishou68 kuishou68 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

  1. 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_options should be omitted
    • Normal providers (OpenAI, DeepSeek, etc.) → stream_options should still be included
    • Invalid/empty URL fallback → should default to including stream_options
  2. Trigger CI — There are no CI checks on this branch yet. Please ensure npm run build && npm run test passes.

Optional (nice-to-have)

  1. Consider extracting strictProviders into a shared constant or config if we expect more providers to be added over time. Not a blocker for this PR though.

  2. The .endsWith('.' + h) subdomain matching for api.cerebras.ai is 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. 👍

@cdxiaodong
Copy link
Author

修复并提交新commit id为:45f92016a7c214a7aaebc3b0afdbe380056acdc4
单测通过图
image
修复前后对比日志

image

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.

2 participants