Python SDK: LangChain Integration

Keito does not ship a keito.integrations.langchain callback package. Use ordinary SDK calls around the invocation you want to record. This keeps retries, failed work and expense pricing under your control.

Wrap an invocation

Install keito and your chosen LangChain packages. Define record_completed_work from the agent integration guide in your own keito_tracking.py module first.

from keito import Keito
from keito_tracking import record_completed_work

# chain is a configured LangChain Runnable from your application.
with Keito() as client:
    result = record_completed_work(
        client,
        project_id="YOUR_PROJECT_ID",
        task_id="YOUR_TASK_ID",
        spent_date="2026-10-30",
        work=lambda: chain.invoke({"input": "Review this implementation"}),
    )

The helper measures the whole invocation once and writes one completed time entry after success. It does not add a callback to every nested chain/tool call, so it avoids counting the same elapsed work at multiple levels.

Record provider usage deliberately

If your provider returns usage metadata, retain nonsensitive counts and a correlation ID in an explicit expense request. Use a known cost or a configured per-unit category; do not assume every model has the same rate. See Expenses.

For async Runnables, use await chain.ainvoke(...), measure that awaited call, then await client.time_entries.create(...). See Async usage. No automatic expense or cleanup behavior is implied.