ReqLLM.Providers.GoogleVertex.Anthropic (ReqLLM v1.16.0)

View Source

Anthropic model family support for Google Vertex AI.

Handles Claude models (Claude 3.5 Haiku, Claude 3.5 Sonnet, Claude Opus, etc.) on Google Vertex AI.

This module acts as a thin adapter between Vertex AI's GCP infrastructure and Anthropic's native message format. It delegates to the native Anthropic modules for all format conversion.

Prompt Caching Support

Full Anthropic prompt caching is supported. Enable with anthropic_prompt_cache: true option.

Extended Thinking Support

Extended thinking (reasoning) is supported for models that support it. Enable with reasoning_effort: "low" | "medium" | "high" option.

Summary

Functions

Decodes Server-Sent Events for streaming responses.

Decodes Server-Sent Events with stateful thinking-block assembly.

Extracts usage metadata from the response body.

Flushes any buffered streaming thinking blocks.

Formats a ReqLLM context into Anthropic request format for Vertex AI.

Initializes streaming state for Claude thinking blocks.

Cleans up thinking config if incompatible with other options.

Parses Anthropic response from Vertex AI into ReqLLM format.

Pre-validates and transforms options for Claude models on Vertex AI. Handles reasoning_effort/reasoning_token_budget translation to thinking config.

Functions

decode_stream_event(event, model)

Decodes Server-Sent Events for streaming responses.

Vertex Claude uses Anthropic's native SSE format.

decode_stream_event(event, model, state)

Decodes Server-Sent Events with stateful thinking-block assembly.

extract_usage(body, model)

Extracts usage metadata from the response body.

Delegates to the native Anthropic provider.

flush_stream_state(model, state)

Flushes any buffered streaming thinking blocks.

format_request(model_id, context, opts)

Formats a ReqLLM context into Anthropic request format for Vertex AI.

Delegates to the native Anthropic.Context module. Vertex AI uses the native Anthropic Messages API format directly.

For :object operations the structured-output strategy depends on anthropic_structured_output_mode (resolved via AdapterHelpers.structured_output_mode/1):

  • :json_schema — sends output_config.format and leaves the tools alone; the model returns the object as message text (grammar-constrained).
  • otherwise (:auto) — injects a synthetic structured_output tool and forces tool choice, relying on Claude's best-effort tool calling.

init_stream_state()

Initializes streaming state for Claude thinking blocks.

maybe_clean_thinking_after_translation(opts, operation)

Cleans up thinking config if incompatible with other options.

Delegates to shared PlatformReasoning module. See ReqLLM.Providers.Anthropic.PlatformReasoning.maybe_clean_thinking_after_translation/2.

parse_response(body, vertex_model, opts)

Parses Anthropic response from Vertex AI into ReqLLM format.

Delegates to the native Anthropic.Response module.

For :object operations, extracts the structured output: from the message text in :json_schema mode (output_config.format), or from the structured_output tool call otherwise. The mode is read from opts, so the caller must forward anthropic_structured_output_mode into response decoding (see decode_response/1).

pre_validate_options(operation, model, opts)

Pre-validates and transforms options for Claude models on Vertex AI. Handles reasoning_effort/reasoning_token_budget translation to thinking config.