ReqLLM.Providers.Anthropic.PlatformReasoning (ReqLLM v1.0.0)

View Source

Shared extended thinking/reasoning support for Anthropic models on third-party platforms.

This module provides common functionality for Anthropic Claude models running on third-party AI platforms that use the additional_model_request_fields approach for extended thinking configuration.

Not for Native Anthropic

Native Anthropic API uses a different approach with additional logic (adjust_max_tokens_for_thinking, adjust_top_p_for_thinking).

Shared Functionality

This module provides:

Platform-Specific Functionality

Each platform maintains its own:

  • maybe_translate_reasoning_params/2 - Platform-specific translation logic (handles model capability checks and calls shared functions)

Summary

Functions

Adds thinking config to provider_options.additional_model_request_fields.

Removes thinking config when incompatible with other parameters.

Functions

add_reasoning_to_additional_fields(opts, budget_tokens)

Adds thinking config to provider_options.additional_model_request_fields.

This is the format used by Bedrock, Vertex, and other third-party platforms that host Anthropic models.

Example

opts = add_reasoning_to_additional_fields(opts, 4000)
# Adds to provider_options:
# additional_model_request_fields: %{
#   thinking: %{type: "enabled", budget_tokens: 4000}
# }

maybe_clean_thinking_after_translation(opts, operation)

Removes thinking config when incompatible with other parameters.

Extended thinking is incompatible with:

  • Forced tool choice (tool_choice: %{type: "tool"})
  • :object operations (which use forced tool choice internally)
  • Temperature != 1.0 (Anthropic-specific constraint)

This should be called AFTER translate_options has run, since translate_options may add or modify tool_choice and temperature.

Example

opts = maybe_clean_thinking_after_translation(opts, :object)
# Removes thinking from additional_model_request_fields if incompatible