DOCS / SDKS / CLAUDE AGENT SDK
VIEW RAW

Claude Agent SDK + humanhours (Python)

Pattern, not a package. This page documents how to wire the Python SDK around a Claude agent run. The Python SDK itself is in preview (see /docs/sdks/python).

The Claude Agent SDK runs autonomous flows; humanhours measures their ROI. The cleanest hookup is the @track decorator from the Python SDK around the function that wraps a single agent run.

from anthropic import Anthropic
from humanhours import Humanhours, track

hh = Humanhours(api_key="hh_live_...")

@track(hh, agent_id="legal-clause-reviewer", task_type="contract_clause_review")
def review_clause(clause_text: str) -> dict:
    client = Anthropic()
    response = client.messages.create(
        model="claude-opus-4-7",
        max_tokens=1024,
        messages=[{"role": "user", "content": f"Review:\n{clause_text}"}],
    )
    return {"text": response.content[0].text}

review_clause("Limit of liability shall not exceed $10,000.")

The decorator handles wall-clock timing and outcome (success on return, failure on raise).

Capturing token cost

For Level 3 ROI (net_saved = cost_saved - agent_cost), pass the cost derived from response usage on the final track() call:

@track(hh, agent_id="legal-clause-reviewer", task_type="contract_clause_review")
def review_clause(text: str) -> dict:
    response = client.messages.create(...)
    # claude-opus-4-7 pricing: $15/M input, $75/M output (illustrative)
    cost = (
        response.usage.input_tokens / 1_000_000 * 15
        + response.usage.output_tokens / 1_000_000 * 75
    )
    return {"text": response.content[0].text, "_humanhours": {"agent_cost": cost}}

Then a tiny adapter on the metadata_fn argument can extract the agent_cost and lift it to the top-level field. A richer wrapper ships once the Python SDK leaves preview; the pattern above works against the API directly today.

Multi-tool agents

Claude agents that call tools across many turns can be wrapped at the task level (one user request -> one tracked event), not the call level (which would multiply events). Pick the granularity that matches what your CFO wants to count.

See also


Found a typo or want to suggest an edit? Email support@triadagency.ai.