package ocaml-ai-sdk

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Ai_provider_anthropic.Convert_promptSource

Convert SDK prompts to Anthropic Messages API format.

Anthropic message content types.

Sourcetype image_source =
  1. | Base64_image of {
    1. media_type : string;
    2. data : string;
    }
  2. | Url_image of {
    1. url : string;
    }
Sourcetype document_source =
  1. | Base64_document of {
    1. media_type : string;
    2. data : string;
    }
Sourcetype anthropic_tool_result_content =
  1. | Tool_text of string
  2. | Tool_image of {
    1. source : image_source;
    }
Sourcetype anthropic_content =
  1. | A_text of {
    1. text : string;
    2. cache_control : Cache_control.t option;
    }
  2. | A_image of {
    1. source : image_source;
    2. cache_control : Cache_control.t option;
    }
  3. | A_document of {
    1. source : document_source;
    2. cache_control : Cache_control.t option;
    }
  4. | A_tool_use of {
    1. id : string;
    2. name : string;
    3. input : Yojson.Basic.t;
    }
  5. | A_tool_result of {
    1. tool_use_id : string;
    2. content : anthropic_tool_result_content list;
    3. is_error : bool;
    4. cache_control : Cache_control.t option;
    }
  6. | A_thinking of {
    1. thinking : string;
    2. signature : string;
    }
  7. | A_redacted_thinking of {
    1. data : string;
    }
Sourcetype anthropic_message = {
  1. role : [ `User | `Assistant ];
  2. content : anthropic_content list;
}

Extract system messages with their per-message provider_options and return remaining messages. The order matches the input.

Sourceval system_to_json : ?validator:Ai_provider_anthropic__.Cache_control_validator.t -> (string * Ai_provider.Provider_options.t) list -> Yojson.Basic.t option

Build the wire JSON for the system field on the Anthropic request. Returns None when no system messages are present. Always emits the array-of-blocks form (one text block per system message), matching upstream @ai-sdk/anthropic's convertToAnthropicPrompt.

Sourceval convert_messages : ?validator:Ai_provider_anthropic__.Cache_control_validator.t -> Ai_provider.Prompt.message list -> anthropic_message list

Convert SDK messages to Anthropic format with message grouping for alternating user/assistant roles. Pass ~validator to share the 4-breakpoint budget with system_to_json and the tools conversion.

Sourceval anthropic_content_to_json : anthropic_content -> Yojson.Basic.t

Serialize a content block to JSON.

Sourceval anthropic_message_to_json : anthropic_message -> Yojson.Basic.t

Serialize a message to JSON.