Installation
Imports
AsyncPikarc
The main client. Creates an underlyinghttpx.AsyncClient configured with your API key.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | required | Your Pikarc API key (lg_<prefix>_<secret>) |
base_url | str | "http://localhost:8000" | Pikarc API server URL |
Methods
run(user_id, metadata?)
Async context manager that starts a guarded run and auto-ends it on exit.
| Parameter | Type | Default | Description |
|---|---|---|---|
user_id | str | required | SDK user identifier (not the dashboard account) |
metadata | dict[str, Any] | None | None | Arbitrary metadata attached to the run |
- On entry: calls
POST /v1/runs/and evaluates guardrails. RaisesPikarcBlockedErrorif denied. - On clean exit: calls
POST /v1/runs/{id}/endwith statusCOMPLETED. - On exception: calls
POST /v1/runs/{id}/endwith statusFAILED, then re-raises.
close()
Closes the underlying HTTP client. Call this when you’re done with the guard instance.
Async Only
The SDK is async-only for the MVP. All methods must be called withawait inside an async context. If you need sync usage, wrap calls with asyncio.run():