package anthropic

  1. Overview
  2. Docs

Module Anthropic.ModelsSource

Models API for querying available Claude models.

This module provides functions to retrieve information about available models and their capabilities.

Sourcetype t = {
  1. id : string;
    (*

    Unique model identifier.

    *)
  2. created_at : string;
    (*

    ISO 8601 timestamp of model creation.

    *)
  3. display_name : string;
    (*

    Human-readable model name.

    *)
  4. type_ : string;
    (*

    Model type (e.g., "chat").

    *)
}

t contains metadata about an available model.

Sourceval get : client -> model_id:string -> unit -> (t, error) result

get client ~model_id () retrieves information about a specific model.

  • parameter model_id

    The model identifier to query.

  • raises Api_error

    if the model doesn't exist or isn't accessible.

Example: Gets details about a specific model.

  match Models.get client ~model_id:"claude-3-5-sonnet-20241022" () with
  | Ok model ->
      Printf.printf "Model %s created at %s\n" model.display_name
        model.created_at
  | Error e -> Printf.eprintf "Error: %s\n" (string_of_error e)
Sourceval list : client -> ?limit:int -> ?after_id:string -> unit -> (t page, error) result

list client ?limit ?after_id () retrieves a paginated list of available models.

  • parameter limit

    Maximum models per page (default: 20).

  • parameter after_id

    Pagination cursor for subsequent pages.

Example: Lists all available models.

  let rec print_models page =
    List.iter
      (fun m -> Printf.printf "- %s (%s)\n" m.display_name m.id)
      page.data;
    match page.get_next_page () with
    | Some (Ok next) -> print_models next
    | Some (Error e) ->
        Printf.eprintf "Pagination error: %s\n" (string_of_error e)
    | None -> ()
  in
  match Models.list client () with
  | Ok page -> print_models page
  | Error e -> Printf.eprintf "Error: %s\n" (string_of_error e)
OCaml

Innovation. Community. Security.