Python SDK: Async Usage
For high-throughput agent work, use the async client to make non-blocking API calls.
Setup
from keito import AsyncKeito
client = AsyncKeito()
The AsyncKeito client accepts the same configuration options as the sync client.
Basic Usage
import asyncio
from keito import AsyncKeito
async def main():
client = AsyncKeito()
# Create a time entry
entry = await client.time_entries.create(
project_id="prj_abc",
task_id="tsk_001",
spent_date="2026-03-06",
hours=1.5,
notes="Async agent work",
source="agent",
)
# List entries
entries = await client.time_entries.list(
source="agent",
project_id="prj_abc",
)
for e in entries.data:
print(f"{e.spent_date}: {e.hours}h")
asyncio.run(main())
Async Context Manager
The track_agent_work context manager works with async with:
async with client.track_agent_work(
project_id="prj_abc",
agent_id="batch-processor",
model="claude-sonnet-4-6",
) as session:
results = await asyncio.gather(*[
process_item(item) for item in items
])
session.report_tokens(input=total_input, output=total_output)
Parallel Agent Work
Process multiple agent tasks concurrently while tracking each one:
async def process_pr(client: AsyncKeito, pr_url: str):
async with client.track_agent_work(
project_id="prj_abc",
task_id="tsk_code_review",
agent_id="review-bot",
model="claude-sonnet-4-6",
) as session:
result = await review_agent.run(pr_url)
session.report_tokens(
input=result.input_tokens,
output=result.output_tokens,
)
session.set_notes(f"Reviewed {pr_url}")
return result
# Process 5 PRs in parallel
results = await asyncio.gather(*[
process_pr(client, url) for url in pr_urls
])
When to Use Async
- Batch processing — processing multiple items concurrently
- Web applications — FastAPI, Starlette, or other async frameworks
- Agent orchestration — running multiple agents in parallel
- High-frequency logging — many short agent tasks in sequence