Skip to main content
This guide takes you from an API key to your first decision. You need Python 3.10 or later and a Krun API key.
1

Install the SDK

The package is krun-ai on PyPI. You import it as krun.
2

Set your API key

The SDK reads the key from the KRUN_API_KEY environment variable.
Keep your API key on the server. Never ship it in browser or mobile client code. See Authentication.
3

Make a decision

Create decide.py:
decide.py
Run it:
4

Handle abstention

When the model is not confident enough, it abstains: answer.choice is None and answer.abstain is True. The probabilities are still there if you want a best guess.
See Abstention for when to trust this signal.
The numbers above come from a real call. Your values can differ slightly between calls and model updates, so don’t hard-code them in tests.

Use the HTTP API directly

The same request with curl:
Response:
The request id is in the X-Request-ID response header (curl -i shows it). You need it to send feedback.
The first request after a period without traffic can take longer while the model starts. The SDK’s default 70-second timeout covers this. See Production best practices.

Next steps

Questions and answers

How requests and answers are structured.

Multiple questions

Ask several questions about the same text in one call.

Tool routing

Pick a tool for an agent step.

Python SDK

Async client, errors, timeouts and retries.