Skip to content

fix(agent): fix OpenAI-compat request body serialization and max_tokens#595

Merged
tlongwell-block merged 1 commit into
mainfrom
fix/openai-compat-request-body
May 15, 2026
Merged

fix(agent): fix OpenAI-compat request body serialization and max_tokens#595
tlongwell-block merged 1 commit into
mainfrom
fix/openai-compat-request-body

Conversation

@tlongwell-block
Copy link
Copy Markdown
Collaborator

Problem

Two issues prevented sprout-agent from working with newer OpenAI models (e.g. gpt-5.5):

  1. max_tokens rejected by newer models: OpenAI's newer models (gpt-5.5, o-series) reject the legacy max_tokens parameter and require max_completion_tokens instead.

  2. Request body silently dropped: The post() helper used reqwest's .json(body) which sets Content-Type AND 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

  • Replace max_tokens with max_completion_tokens in both OpenAI request paths (openai_body() and summarize())
  • Switch post() to manual serialization via serde_json::to_vec() + .body() + explicit Content-Type header
  • Remove duplicate content-type headers from all callers

Testing

  • ✅ All 17 sprout-agent unit tests pass
  • ✅ Full workspace cargo test passes (2 flaky pair-relay timing tests fail identically on main)
  • cargo clippy --workspace clean
  • cargo fmt clean
  • ✅ Live tested with gpt-5.5: simple prompt + tool use (MCP shell)
  • ✅ Anthropic regression test: claude-haiku-4-5 still works correctly

Notes

  • max_completion_tokens is the standard for all current OpenAI models. Some older OpenAI-compatible servers (vLLM, Ollama) may still only accept max_tokens — if that's a concern, a follow-up could add a config knob or send both.

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 tlongwell-block merged commit 9e94a7c into main May 15, 2026
15 checks passed
@tlongwell-block tlongwell-block deleted the fix/openai-compat-request-body branch May 15, 2026 15:07
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)
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.

1 participant