Skip to content

fix(llm): GPT-5 needs max_completion_tokens; bump xAI default to grok-4.3#31

Merged
paulgnz merged 1 commit into
mainfrom
fix/llm-openai-max-tokens-xai-grok-4.3
May 22, 2026
Merged

fix(llm): GPT-5 needs max_completion_tokens; bump xAI default to grok-4.3#31
paulgnz merged 1 commit into
mainfrom
fix/llm-openai-max-tokens-xai-grok-4.3

Conversation

@paulgnz
Copy link
Copy Markdown
Collaborator

@paulgnz paulgnz commented May 22, 2026

Live smoke test of the multi-LLM path (PR #27) caught two real issues that the type system + factory tests didn't.

Bug — OpenAI completion fails with 400 on GPT-5

GPT-5 / o-series reject max_tokens with:

400 Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.

xAI's OpenAI-compatible API still uses max_tokens. Fix branches on provider flavor:

  • provider === 'openai'max_completion_tokens
  • provider === 'xai'max_tokens (unchanged)

End-to-end smoke tests now GREEN for both providers

OpenAI / gpt-5:

  • Factory wiring ✓
  • Text completion ✓ (GPT-5 caveat: short max_tokens can leave empty content due to internal reasoning tokens; default 4096 is fine)
  • Tool-use call ✓ — assistant called get_time
  • Tool-result roundtrip ✓ — "It's 07:00 UTC on 2026-05-22..."

xAI / grok-4.3:

  • Factory wiring ✓
  • Text completion ✓ — "verified" in 1 token, clean end_turn
  • Tool-use call ✓
  • Tool-result roundtrip ✓ — "The current time is 2026-05-22T07:00:00Z"

Default model bump — grok-3-latest → grok-4.3

xAI released grok-4.3 since we shipped 0.5.0; the default now picks it up. Operators with AGENT_MODEL=grok-3-latest explicit are unaffected.

What's still untested

Gemini path is in code but unverified end-to-end (no key available during this session). Treat as "best-effort" until exercised.

Versions

  • @xpr-agents/openclaw0.5.2 (patch)
  • create-xpr-agent0.7.2 (patch)

Verification

  • 80 openclaw tests pass
  • Agent runner + frontend build clean
  • OpenAI smoke: factory + text + tool-use + tool-result ✓
  • xAI smoke: same four checkpoints ✓

…-4.3

Live smoke test of the multi-LLM path (PR #27) caught two real
issues that the type system + factory tests didn't.

## Bug — OpenAI completion fails with 400 on GPT-5

GPT-5 (and the o-series) rejects the legacy `max_tokens` field with:

  400 Unsupported parameter: 'max_tokens' is not supported with this
      model. Use 'max_completion_tokens' instead.

The OpenAI SDK passes the field through unmodified, so `LlmClient`
needed to send the right name. xAI's OpenAI-compatible API still
uses `max_tokens` though, so the fix branches on provider flavor:

  - provider === 'openai' → max_completion_tokens
  - provider === 'xai'    → max_tokens (unchanged)

End-to-end smoke tests now green for both providers:

  [1] factory: openai / gpt-5
  [3] tool-use stop: tool_use, 1 tool call → get_time
  [4] tool-result roundtrip: "It's 07:00 UTC..."

  [1] factory: xai / grok-4.3
  [2] text stop: end_turn, "verified" in 1 token
  [3] tool-use: 1 call to get_time
  [4] roundtrip: "The current time is 2026-05-22T07:00:00Z"

Note for operators on GPT-5: the model uses internal reasoning
tokens that count against `max_tokens`. With a tight ceiling (say
30) it may return empty content with stop_reason=max_tokens. The
default 4096 is fine; just don't lower it aggressively when using
gpt-5.

## Default model bump — grok-3-latest → grok-4.3

xAI released grok-4.3 since we shipped 0.5.0; updating the default
gives new operators the current generation. Existing users who set
AGENT_MODEL=grok-3-latest explicitly are unaffected.

Updated in:
  - openclaw/starter/agent/src/llm/types.ts (DEFAULT_MODELS.xai)
  - README + QUICKSTART tables across all surfaces
  - start.sh help text (3 occurrences per file)

## Versions

  @xpr-agents/openclaw → 0.5.2 (patch — fix only)
  create-xpr-agent     → 0.7.2 (patch — model default in scaffold)

## What's still untested

Gemini path is in code but unverified end-to-end (no key available
during this session). Most-different SDK + message shape of the
four impls; treat as "best-effort" until someone exercises it with
a real key. The structural code path matches the OpenAI one, but
Gemini's `functionResponse` part shape + 'function' role for tool
results is unique to that impl.

## Verification

- 80 openclaw tests pass
- Agent runner builds clean (tsc no errors)
- Frontend rebuild clean (all 13 routes prerendered)
- OpenAI smoke test (gpt-5): factory + text + tool-use + tool-result roundtrip ✓
- xAI smoke test (grok-4.3): same four checkpoints ✓
@paulgnz paulgnz merged commit daa1c15 into main May 22, 2026
5 checks passed
@paulgnz paulgnz deleted the fix/llm-openai-max-tokens-xai-grok-4.3 branch May 22, 2026 08:16
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