Repository navigation
Conversation
…okens on 400 The streaming path always sent max_tokens + temperature and had no fallback, so GPT-5 / reasoning models failed with an 'unsupported parameter: max_tokens' error. The non-streaming send() already retries with max_completion_tokens; the streaming comment claimed to fall back to it but never did. On a 400 naming max_tokens/max_completion_tokens/temperature/unsupported (raised before any delta is emitted), fall back to send() and emit the reply as a single delta. Applied to OpenAIClient and CustomClient. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015crzUUNTK64Y8i8QgJDkaz
GPT-5 can take over 60s before sending the first byte, which tripped the default URLSession idle timeout and surfaced as a network error on the non-streaming fallback. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015crzUUNTK64Y8i8QgJDkaz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Using GPT-5 (or any reasoning model) with the OpenAI or Custom provider on iOS fails with an unsupported
max_tokens/max_completion_tokenserror.The chat reply goes through
stream(), which always sendsmax_tokens+temperatureand has no fallback. The non-streamingsend()already retries withmax_completion_tokensand notemperature, and the doc comment onstream()says it falls back tosend's retry, but the code never did.Fix
In
OpenAIClient.streamandCustomClient.stream, catch a400whose body mentionsmax_completion_tokens,max_tokens,temperatureorunsupported(same match assend). That error arrives before any delta, so fall back tosend()(which retries with the modern params) and emit the reply as one delta. Other errors are rethrown unchanged.Trade-off: those models' replies appear all at once instead of streaming. Switching the streaming request itself to the modern params on retry would be a larger change; happy to do that if preferred.
Second commit
Raises
timeoutIntervalto 300s on the non-streaming OpenAI/Custom chat requests so the fallback does not time out while a reasoning model is thinking.Testing
xcodebuild -scheme NOOPiOSbuilds clean.Not touched: Android.
AiCoach.kthas its own request path; I haven't checked it for the same gap.