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 up to about 2 minutes while the model loads. Use a client timeout of at least 180 seconds (the SDK default from version 0.3.0) and retry 504 UPSTREAM_TIMEOUT. 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.