Skip to content

fix: relax service_tier validation for OpenRouter responses#44

Merged
timeleft-- merged 1 commit intomainfrom
fix/openrouter-service-tier-validation
May 5, 2026
Merged

fix: relax service_tier validation for OpenRouter responses#44
timeleft-- merged 1 commit intomainfrom
fix/openrouter-service-tier-validation

Conversation

@timeleft--
Copy link
Copy Markdown
Member

Summary

  • Monkey-patch ChatCompletion.service_tier to accept str | None at module load, fixing a Pydantic ValidationError when OpenRouter returns service_tier: "standard" (outside the OpenAI SDK's strict Literal set)
  • any-llm-sdk inherits the strict type and revalidates responses in _convert_chat_completion, so fava-trails cannot recover the already-paid response from a wrapper
  • Adds a regression test that validates ChatCompletion accepts non-standard service_tier values after the patch

Context

Trust gate propose_truth consistently errors on thoughts (e.g. 01KQVCSTJ6CKM8H2YEZFFBTW70) with:

Failed to parse reviewer response after retry: 1 validation error for ChatCompletion
service_tier
  Input should be 'auto', 'default', 'flex', 'scale' or 'priority'
  [input_value='standard', input_type=str]

Test plan

  • test_chatcompletion_accepts_nonstandard_service_tier — verifies the patch works
  • Full suite: 619 passed, 0 failures

🤖 Generated with Claude Code

OpenRouter returns service_tier: "standard" which falls outside the
OpenAI SDK's Literal["auto","default","flex","scale","priority"].
any-llm-sdk inherits this strict type and revalidates responses,
causing propose_truth to fail with a Pydantic ValidationError.

Monkey-patch ChatCompletion.service_tier to accept str | None at
module load. Includes a regression test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timeleft-- timeleft-- merged commit 4339adb into main May 5, 2026
7 checks passed
@timeleft-- timeleft-- deleted the fix/openrouter-service-tier-validation branch May 5, 2026 14:49
@timeleft-- timeleft-- mentioned this pull request May 5, 2026
2 tasks
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