Packages

A Gleam framework for building AI agents — type-safe, multi-provider, with tool calling, streaming, and simulation testing

Current section

Files

Jump to
glean src glean@models@anthropic.erl
Raw

src/glean@models@anthropic.erl

-module(glean@models@anthropic).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glean/models/anthropic.gleam").
-export([max_output_tokens/2, temperature/2, top_p/2, top_k/2, stop_sequences/2, build/1, opus_4_6/1, sonnet_4_6/1, haiku_4_5/1, opus_4_5/1, sonnet_4_5/1, opus_4_1/1, sonnet_4/1, opus_4/1, haiku_3/1, haiku_3_5/1]).
-export_type([claude/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Anthropic Claude models.\n"
"\n"
" Covers Claude Opus, Sonnet, and Haiku families.\n"
" Supported parameters: max_output_tokens, temperature, top_p, top_k,\n"
" stop_sequences.\n"
"\n"
" All Claude models share the same parameter support. No seed or penalty\n"
" parameters are available.\n"
).
-opaque claude() :: {claude,
binary(),
binary(),
gleam@option:option(integer()),
gleam@option:option(float()),
gleam@option:option(float()),
gleam@option:option(integer()),
gleam@option:option(list(binary())),
gleam@option:option({binary(), binary()})}.
-file("src/glean/models/anthropic.gleam", 140).
?DOC(" Set the maximum number of output tokens.\n").
-spec max_output_tokens(claude(), integer()) -> claude().
max_output_tokens(M, N) ->
{claude,
erlang:element(2, M),
erlang:element(3, M),
{some, N},
erlang:element(5, M),
erlang:element(6, M),
erlang:element(7, M),
erlang:element(8, M),
erlang:element(9, M)}.
-file("src/glean/models/anthropic.gleam", 145).
?DOC(" Set the sampling temperature (0-1).\n").
-spec temperature(claude(), float()) -> claude().
temperature(M, T) ->
{claude,
erlang:element(2, M),
erlang:element(3, M),
erlang:element(4, M),
{some, T},
erlang:element(6, M),
erlang:element(7, M),
erlang:element(8, M),
erlang:element(9, M)}.
-file("src/glean/models/anthropic.gleam", 150).
?DOC(" Set the top-p (nucleus sampling) value (0-1).\n").
-spec top_p(claude(), float()) -> claude().
top_p(M, P) ->
{claude,
erlang:element(2, M),
erlang:element(3, M),
erlang:element(4, M),
erlang:element(5, M),
{some, P},
erlang:element(7, M),
erlang:element(8, M),
erlang:element(9, M)}.
-file("src/glean/models/anthropic.gleam", 155).
?DOC(" Set the top-k sampling value.\n").
-spec top_k(claude(), integer()) -> claude().
top_k(M, K) ->
{claude,
erlang:element(2, M),
erlang:element(3, M),
erlang:element(4, M),
erlang:element(5, M),
erlang:element(6, M),
{some, K},
erlang:element(8, M),
erlang:element(9, M)}.
-file("src/glean/models/anthropic.gleam", 161).
?DOC(
" Set stop sequences — the model will stop generating when it encounters\n"
" any of these strings.\n"
).
-spec stop_sequences(claude(), list(binary())) -> claude().
stop_sequences(M, Stops) ->
{claude,
erlang:element(2, M),
erlang:element(3, M),
erlang:element(4, M),
erlang:element(5, M),
erlang:element(6, M),
erlang:element(7, M),
{some, Stops},
erlang:element(9, M)}.
-file("src/glean/models/anthropic.gleam", 173).
?DOC(
" Build a `Model` from this Claude configuration.\n"
"\n"
" If the model is deprecated, a warning is printed and the replacement\n"
" model ID is used instead.\n"
).
-spec build(claude()) -> glean@model:model().
build(M) ->
Actual_model_id = case erlang:element(9, M) of
none ->
erlang:element(3, M);
{some, {Replacement, Shutdown}} ->
glean@model:deprecation_warning(
erlang:element(3, M),
Replacement,
Shutdown
),
Replacement
end,
Provider = glean@providers@anthropic:new(
erlang:element(2, M),
Actual_model_id
),
Settings = {model_settings,
erlang:element(4, M),
erlang:element(5, M),
erlang:element(6, M),
erlang:element(7, M),
erlang:element(8, M),
none,
none,
none},
{model, Provider, Settings}.
-file("src/glean/models/anthropic.gleam", 204).
-spec new_claude(binary(), binary()) -> claude().
new_claude(Api_key, Model_id) ->
{claude, Api_key, Model_id, none, none, none, none, none, none}.
-file("src/glean/models/anthropic.gleam", 36).
?DOC(" Claude Opus 4.6 — latest and most capable model.\n").
-spec opus_4_6(binary()) -> claude().
opus_4_6(Key) ->
new_claude(Key, <<"claude-opus-4-6"/utf8>>).
-file("src/glean/models/anthropic.gleam", 41).
?DOC(" Claude Sonnet 4.6 — balanced performance and speed.\n").
-spec sonnet_4_6(binary()) -> claude().
sonnet_4_6(Key) ->
new_claude(Key, <<"claude-sonnet-4-6"/utf8>>).
-file("src/glean/models/anthropic.gleam", 46).
?DOC(" Claude Haiku 4.5 — fast and cost-effective.\n").
-spec haiku_4_5(binary()) -> claude().
haiku_4_5(Key) ->
new_claude(Key, <<"claude-haiku-4-5-20251001"/utf8>>).
-file("src/glean/models/anthropic.gleam", 217).
-spec new_deprecated_claude(binary(), binary(), binary(), binary()) -> claude().
new_deprecated_claude(Api_key, Model_id, Replacement, Shutdown) ->
{claude,
Api_key,
Model_id,
none,
none,
none,
none,
none,
{some, {Replacement, Shutdown}}}.
-file("src/glean/models/anthropic.gleam", 56).
?DOC(" Claude Opus 4.5 — legacy, will be replaced by claude-opus-4-6.\n").
-spec opus_4_5(binary()) -> claude().
opus_4_5(Key) ->
new_deprecated_claude(
Key,
<<"claude-opus-4-5-20251101"/utf8>>,
<<"claude-opus-4-6"/utf8>>,
<<"Nov 24, 2026"/utf8>>
).
-file("src/glean/models/anthropic.gleam", 67).
?DOC(" Claude Sonnet 4.5 — legacy, will be replaced by claude-sonnet-4-6.\n").
-spec sonnet_4_5(binary()) -> claude().
sonnet_4_5(Key) ->
new_deprecated_claude(
Key,
<<"claude-sonnet-4-5-20250929"/utf8>>,
<<"claude-sonnet-4-6"/utf8>>,
<<"Sep 29, 2026"/utf8>>
).
-file("src/glean/models/anthropic.gleam", 78).
?DOC(" Claude Opus 4.1 — legacy, will be replaced by claude-opus-4-6.\n").
-spec opus_4_1(binary()) -> claude().
opus_4_1(Key) ->
new_deprecated_claude(
Key,
<<"claude-opus-4-1-20250805"/utf8>>,
<<"claude-opus-4-6"/utf8>>,
<<"Aug 5, 2026"/utf8>>
).
-file("src/glean/models/anthropic.gleam", 89).
?DOC(" Claude Sonnet 4 — legacy, will be replaced by claude-sonnet-4-6.\n").
-spec sonnet_4(binary()) -> claude().
sonnet_4(Key) ->
new_deprecated_claude(
Key,
<<"claude-sonnet-4-20250514"/utf8>>,
<<"claude-sonnet-4-6"/utf8>>,
<<"May 14, 2026"/utf8>>
).
-file("src/glean/models/anthropic.gleam", 100).
?DOC(" Claude Opus 4 — legacy, will be replaced by claude-opus-4-6.\n").
-spec opus_4(binary()) -> claude().
opus_4(Key) ->
new_deprecated_claude(
Key,
<<"claude-opus-4-20250514"/utf8>>,
<<"claude-opus-4-6"/utf8>>,
<<"May 14, 2026"/utf8>>
).
-file("src/glean/models/anthropic.gleam", 115).
?DOC(" Claude 3 Haiku — deprecated, will be replaced by claude-haiku-4-5.\n").
-spec haiku_3(binary()) -> claude().
haiku_3(Key) ->
new_deprecated_claude(
Key,
<<"claude-3-haiku-20240307"/utf8>>,
<<"claude-haiku-4-5-20251001"/utf8>>,
<<"Apr 20, 2026"/utf8>>
).
-file("src/glean/models/anthropic.gleam", 126).
?DOC(" Claude 3.5 Haiku — deprecated, already retired.\n").
-spec haiku_3_5(binary()) -> claude().
haiku_3_5(Key) ->
new_deprecated_claude(
Key,
<<"claude-3-5-haiku-20241022"/utf8>>,
<<"claude-haiku-4-5-20251001"/utf8>>,
<<"Feb 2026 (retired)"/utf8>>
).