fix(agent): fix OpenAI-compat request body serialization and max_tokens#595
Merged
Conversation
Two issues prevented sprout-agent from working with newer OpenAI models
(e.g. gpt-5.5):
1. max_tokens → max_completion_tokens: Newer OpenAI models reject the
legacy 'max_tokens' parameter and require 'max_completion_tokens'.
2. Request body dropped by reqwest 0.13: The post() helper used
.json(body) which sets Content-Type AND serializes the body, but
callers then added .header("content-type", "application/json")
via the closure. This caused reqwest to silently drop the body,
resulting in OpenAI returning 'you must provide a model parameter'.
Fix: Switch post() to manual serialization via serde_json::to_vec()
+ .body() + explicit Content-Type header, removing duplicate headers
from all callers.
tlongwell-block
added a commit
that referenced
this pull request
May 15, 2026
* origin/main: (33 commits) dev-mcp: add view_image tool (#602) fix(relay,desktop): only advertise NIP-43 when enforced; probe pairing by supported_nips (#601) fix(desktop): derive unread state from NIP-RS + relay catch-up only (#599) docs(testing): rewrite TESTING.md for current API and CLI-first workflow (#597) fix(agent): fix OpenAI-compat request body serialization and max_tokens (#595) feat(desktop): per-persona and per-agent env var overrides (#594) fix(desktop): stop pinning agents to deprecated SPROUT_ACP_TURN_TIMEOUT (#592) fix(desktop): populate member_count in get_channels so channel browser shows real counts (#548) fix(desktop): autofocus message composer on channel/thread open (#572) refactor(cli): restructure flat commands into 12 subcommand groups (#585) feat(sdk): add builder functions for workflows, DMs, and presence (#589) feat(desktop): add message more-actions dropdown menu (#590) fix(mobile): preserve channel list across background/resume reconnection (#588) Redesign Home as an inbox (#582) fix(desktop): drive unread badges from live subscription, not refetched lastMessageAt (#581) fix(desktop): refine header scaling and shadow (#573) fix(desktop): keep day dividers below header (#574) Move agent activity below composer (#579) docs(nips): NIP-AE — Agent Engrams (#575) refactor: extract shared @mention resolver into sprout-sdk (#580) ... Signed-off-by: Tyler Longwell <tlongwell@squareup.com>
tlongwell-block
added a commit
that referenced
this pull request
May 15, 2026
Signed-off-by: Tyler Longwell <tlongwell@squareup.com> * origin/main: dev-mcp: add view_image tool (#602) fix(relay,desktop): only advertise NIP-43 when enforced; probe pairing by supported_nips (#601) fix(desktop): derive unread state from NIP-RS + relay catch-up only (#599) docs(testing): rewrite TESTING.md for current API and CLI-first workflow (#597) fix(agent): fix OpenAI-compat request body serialization and max_tokens (#595) feat(desktop): per-persona and per-agent env var overrides (#594)
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
Two issues prevented sprout-agent from working with newer OpenAI models (e.g. gpt-5.5):
max_tokensrejected by newer models: OpenAI's newer models (gpt-5.5, o-series) reject the legacymax_tokensparameter and requiremax_completion_tokensinstead.Request body silently dropped: The
post()helper used reqwest's.json(body)which setsContent-TypeAND serializes the body. Callers then added.header("content-type", "application/json")via the closure, causing reqwest 0.13 to silently drop the request body. OpenAI returned"you must provide a model parameter"because it received an empty body.Fix
max_tokenswithmax_completion_tokensin both OpenAI request paths (openai_body()andsummarize())post()to manual serialization viaserde_json::to_vec()+.body()+ explicitContent-Typeheadercontent-typeheaders from all callersTesting
cargo testpasses (2 flaky pair-relay timing tests fail identically on main)cargo clippy --workspacecleancargo fmtcleanNotes
max_completion_tokensis the standard for all current OpenAI models. Some older OpenAI-compatible servers (vLLM, Ollama) may still only acceptmax_tokens— if that's a concern, a follow-up could add a config knob or send both.