Plugins / Providers

elelem-anthropic

Claude, direct or on Vertex.

Connects elelem to Claude through the Anthropic Messages API, or through Google Cloud Vertex AI. One gem, two providers.

gem install elelem-anthropic

elelem-anthropic connects elelem to Claude. It registers two providers: anthropic calls the Anthropic Messages API with your API key, and vertex calls the same models through Google Cloud Vertex AI with your gcloud credentials. Use it when you want a hosted model and already pay Anthropic or Google.

Install #

gem install elelem elelem-builtins elelem-anthropic

elelem-builtins is optional but gives the agent its default tools. Requires Ruby 4.0.

Configure #

For the Anthropic API, set your key:

export ANTHROPIC_API_KEY=sk-ant-...

For Vertex AI, log in with application default credentials and name your project:

gcloud auth application-default login
export GOOGLE_CLOUD_PROJECT=my-project

The vertex provider runs gcloud auth application-default print-access-token before every request and sends the result as a bearer token, so gcloud must be on your PATH.

--model overrides ANTHROPIC_MODEL or VERTEX_MODEL. The defaults are whatever model IDs the gem shipped with. Pass --model if you want a specific or newer model.

Use #

elelem -p anthropic
elelem -p anthropic --model claude-sonnet-4-5
elelem ask -p anthropic "summarize the README"

When you pass -p anthropic, elelem requires elelem/anthropic on demand. That file registers both providers, but -p vertex makes elelem look for elelem/vertex, which does not exist. Load the gem first with a plugin file:

mkdir -p ~/.agents/plugins
echo 'require "elelem/anthropic"' > ~/.agents/plugins/anthropic.rb
elelem -p vertex

elelem loads every .rb file in ~/.agents/plugins and .agents/plugins before it builds the provider.

The gem also installs elelem-anthropic, which is elelem with anthropic as the default provider:

elelem-anthropic chat
elelem-anthropic ask "what does lib/elelem/cli.rb do?"

Unlike elelem, elelem-anthropic does not load elelem-builtins, so the agent has no tools unless a plugin file adds them.

How it works #

Both providers share one class, Elelem::Anthropic::Provider. Each turn is one POST with stream: true and max_tokens: 64000, made with Net::HTTP. The read timeout is 3600 seconds and the open timeout is 10.

  • anthropic posts to https://api.anthropic.com/v1/messages with anthropic-version: 2023-06-01.
  • vertex posts to https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/REGION/publishers/anthropic/models/MODEL:rawPredict. The model goes in the URL, and the body carries anthropic_version: vertex-2023-10-16 instead of a model field.

Before sending, the provider moves the system message into the system field, turns elelem’s tool results into tool_result blocks, and turns assistant tool calls into tool_use blocks. Tools are sent with their JSON schema as input_schema, and only when there are tools to send.

The response is read as server-sent events. Text deltas become the reply, thinking_delta events are printed as thinking, and input_json_delta fragments are joined and parsed into tool calls when the stream ends. elelem prints thinking as it arrives and the reply once the turn is done.

Limitations #

  • The request never enables extended thinking, so thinking text only appears if the API sends it unasked.
  • max_tokens is fixed at 64,000. There is no setting for it, temperature, or other sampling parameters.
  • Any non-2xx response raises HTTP CODE: BODY. There are no retries.
  • No prompt caching: the request sets no cache_control.
  • -p vertex needs elelem/anthropic loaded first (see above).

Development #

git clone https://git.mokhan.ca/elelem/anthropic.git
cd anthropic
bin/setup
bin/test
bin/lint

The spec injects a fake HTTP adapter, so the tests make no network calls.

Environment #

VariableDefaultDescription
ANTHROPIC_API_KEYnoneRequired for -p anthropic. Sent as the x-api-key header.
ANTHROPIC_MODELclaude-opus-4-5-20250514Model for -p anthropic when –model is not given.
VERTEX_MODELclaude-opus-4-5@20251101Model for -p vertex when –model is not given. Part of the request URL.
GOOGLE_CLOUD_PROJECTnoneRequired for -p vertex. The Google Cloud project that hosts the model.
GOOGLE_CLOUD_REGIONus-east5Vertex AI region for -p vertex.