Packages

Gleam SDK for the Anthropic Claude API with agentic tool-use loop and BEAM concurrency

Current section

Files

Jump to
claude_gleam src claude@client.erl
Raw

src/claude@client.erl

-module(claude@client).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/claude/client.gleam").
-export([new/1, with_model/2, with_base_url/2, with_max_tokens/2]).
-export_type([config/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.
-type config() :: {config, binary(), binary(), binary(), integer()}.
-file("src/claude/client.gleam", 17).
?DOC(
" Create a new Config with sensible defaults.\n"
"\n"
" Defaults:\n"
" - base_url: \"https://api.anthropic.com\"\n"
" - default_model: \"claude-sonnet-4-5-20250929\"\n"
" - default_max_tokens: 4096\n"
).
-spec new(binary()) -> config().
new(Api_key) ->
{config,
Api_key,
<<"https://api.anthropic.com"/utf8>>,
<<"claude-sonnet-4-5-20250929"/utf8>>,
4096}.
-file("src/claude/client.gleam", 27).
?DOC(" Set the model on the config.\n").
-spec with_model(config(), binary()) -> config().
with_model(Config, Model) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
Model,
erlang:element(5, Config)}.
-file("src/claude/client.gleam", 32).
?DOC(" Set the base URL on the config.\n").
-spec with_base_url(config(), binary()) -> config().
with_base_url(Config, Url) ->
{config,
erlang:element(2, Config),
Url,
erlang:element(4, Config),
erlang:element(5, Config)}.
-file("src/claude/client.gleam", 37).
?DOC(" Set the default max tokens on the config.\n").
-spec with_max_tokens(config(), integer()) -> config().
with_max_tokens(Config, Max_tokens) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
Max_tokens}.