feat: add support for Anthropic's strict tool use #304
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.
Description
Adds support for Anthropic's strict tool use feature, which validates tool parameters to ensure Claude calls functions with correctly-typed arguments. This is useful for building reliable agentic workflows where type-safe function calls are critical.
When
strictToolUse: trueis set in chat settings:strict: trueto each tool definition in the request bodyanthropic-beta: structured-outputs-2025-11-13headerUsage:
Reference: https://docs.anthropic.com/en/docs/build-with-claude/tool-use/strict-tool-use
Implementation Details
strictToolUse?: booleansetting toOpenRouterChatSettingsgetStrictToolUseHeaders()helper method for beta header injectiongetArgs()to conditionally includestrict: truedoGenerate()anddoStream()to include headers when enabledNotes
false), so existing behavior is unchangedanthropic-betaheader is sent wheneverstrictToolUseis enabled, even if no tools are in the requestChecklist
pnpm stylecheckandpnpm typecheckpnpm testand all tests passChangeset
pnpm changesetto create a changeset fileReview & Testing Checklist for Human
strict: trueplacement: The property is added at the tool level (alongsidetype: 'function'), not inside thefunctionobject. Confirm this matches OpenRouter's expected format for Anthropic models.structured-outputs-2025-11-13should be checked against current Anthropic docs.Recommended test plan:
strictToolUse: trueanthropic/claude-3.5-sonnet) with a tool that has strict schema requirementsRequested by: Tomas Oliva (@ping-Toven)
Devin session: https://app.devin.ai/sessions/b201995bb0ef4d1f8fa8a6531de0f6fb