Install for the Anthropic SDK¶
The Anthropic SDK has no hook or settings file, so there is nothing for
alr install to wire. You add one call to your own code, after each request.
You need the alr-emit package where your code runs: install it the way
Quickstart step 2 does, or into your project's own
environment.
What alr install claude-sdk Does¶
alr install claude-sdk
What you will see. The command writes nothing, so there is
nothing to apply with --yes. Its preview says so and prints the few lines of
code to add:
from alr_emit import JsonlSink
from alr_emit.adapters.sdk import record_from_sdk_usage
response = client.messages.create(...)
record_from_sdk_usage(response.usage, agent_id="my-agent",
model=response.model, sink=JsonlSink())
record_from_sdk_usage takes a response's usage object directly. Attribute-shaped
SDK objects and plain dicts both work. JsonlSink() appends the record to the same
record file the other harnesses use, so alr summary reads it with the rest.
Then fetch the latest price book with alr prices update: see
Get the Latest Price Book.
Tags come from these layers, lowest first:
- A trusted project config's
default_tagsand a.alr-tagsfile, both found from the working directory of your process. - The user config's
default_tags. $ALR_TAGS.- The session's tag file,
sessions/anthropic-sdk/<session id>.tagsin the OpenALR home.
One Record per Turn¶
If your code runs its own agent loop, where one user turn is several API calls
around tool executions, use SdkSession to write one record per turn:
from alr_emit import JsonlSink
from alr_emit.adapters.sdk import SdkSession
session = SdkSession("my-agent", sink=JsonlSink())
turn = session.turn() # turn_index 1
turn.add(first_response.usage) # once per API call in the tool loop
turn.add(second_response.usage)
turn.end() # ONE record, llm_calls 2
Tokens are summed over the calls. Call session.turn() before the first API
request: the turn's start time is when you call it. Calling end() twice, or
add() after end(), raises ValueError.
OpenALR never prices an SDK call. turn.end(cost_usd=...) records a figure you
supply yourself, and the default is a cost of null, which means unknown. Every
adapter records outcome: "ok": a record meters the labor performed, it does not
judge whether the task succeeded.
Check It¶
Run your code once, then:
alr summary
alr turns last
alr check
Uninstall and Purge¶
alr uninstall claude-sdk # changes nothing; says that nothing was written
alr uninstall claude-sdk --purge --yes # deletes the records your SDK code wrote
The install wrote nothing, so there is nothing to remove. alr uninstall
claude-sdk changes nothing and says that nothing was written. To stop
recording, remove the lines you added from your code. Your records are kept
unless you pass --purge.
--purge deletes only the records written through the SDK adapter from the
shared record file, and the grades, cost corrections, and tag events that name only
those records. Every other harness's records stay, byte for byte. Without
--yes, --purge previews: per file, how many documents it would delete and how
many stay. A line the purge cannot read is never deleted, and the purge names it.
Why It Works This Way¶
- The code is yours, so the call is yours. An SDK client is not a program with a settings file that OpenALR can edit. The only honest install is to show you the call and let you place it.
- The adapter never prices. A cost OpenALR did not receive is unknown, not zero. Pass the figure you have, or leave it null.
- Outcome is
ok. OpenALR meters labor. Whether the task succeeded is a grade you add afterwards withalr grade.
Next: tag your work.