Metadata-Version: 2.5
Name: kitani
Version: 0.2.1
Summary: Python SDK and agent-first CLI for Kitani inference and prepaid billing
Project-URL: Repository, https://github.com/kitani-inc/kitani-cli
Project-URL: Documentation, https://kitani.ai/agents
Requires-Python: >=3.10
Requires-Dist: httpx<1,>=0.27
Requires-Dist: packaging>=24
Provides-Extra: test
Requires-Dist: pytest<10,>=8; extra == 'test'
Provides-Extra: wallet
Requires-Dist: bittensor-wallet<5,>=4; extra == 'wallet'
Requires-Dist: substrate-interface<2,>=1.7; extra == 'wallet'
Description-Content-Type: text/markdown

# Kitani CLI and Python SDK

Authorize a Kitani account, fund its prepaid balance, and run inference from a terminal. Commands work interactively or emit JSON for agent runners. The Python client reuses HTTP connections and streams model output without buffering the entire response.

[PyPI](https://pypi.org/project/kitani/) · [Agents](https://kitani.ai/agents) · [Agent skill](https://github.com/kitani-inc/kitani-cli/blob/main/skills/kitani/SKILL.md) · [API documentation](https://kitani.ai/docs/agents)

## Install

Requires Python 3.10 or later. Install the released CLI from PyPI with pipx:

```sh
pipx install kitani
kitani --version
```

For the Python SDK, run `python -m pip install kitani` in your virtual environment. For local wallet signing, install `'kitani[wallet]'`. To install the development version from source, run `pipx install 'git+https://github.com/kitani-inc/kitani-cli.git'` or `pipx install .` from a clone.

If you installed the earlier `kitani-cli` package through pipx, run `pipx uninstall kitani-cli` and then `pipx install kitani`. For a pip environment, run `python -m pip uninstall kitani-cli` before installing `kitani`. Both packages provide the same Python module and terminal command. Your saved Kitani profile is separate from the package installation.

Interactive commands check PyPI at most once per day per profile and print the upgrade command to stderr when a newer stable release supports your Python version. For a standard pipx install, run `pipx upgrade kitani`. JSON output, redirected streams, CI, and `doctor --offline` skip the check. Set `KITANI_NO_UPDATE_CHECK=1` to disable it.

## First inference request

1. Run `kitani signup`. Confirm the displayed code on kitani.ai, choose a new fingerprint-only account or sign into an existing account, and complete Turnstile. For SSH or CI, run `kitani signup --no-browser --json`, give the verification URL and code to the person approving, then run `kitani signup --resume` in the original profile. Approval expires after ten minutes.
2. Run `kitani whoami` and `kitani keys create --name agent`. The CLI saves the inference key. Preserve the fingerprint for an email-less account in a password manager. Use `kitani keys export fingerprint` in a private terminal or pipe its output into your secret store.
3. Run `kitani fund link --via paypal --usd 10 --json`. Share the returned `payment_url` with the payer. Check the credit with `kitani fund status PAYMENT_ID --wait`.
4. Run `kitani models --json`, then `kitani chat --model MODEL_ID "Hello from Kitani"` with an available model ID. Add `--stream` for incremental text or `--stream --json` for newline-delimited JSON.

## Model catalog and pricing

```sh
kitani models                             # list model IDs
kitani models qwen/qwen3.8-27b-uncensored --json
kitani pricing --online                   # rates and reported online miners
kitani pricing qwen/qwen3.8-27b-uncensored --json
```

Pricing comes from the same public snapshot as the website. Input, output and cached prices are USD per million tokens. Image rates are USD per image. The network total counts unique online miners; a miner may serve several models. Missing coverage is shown as unavailable. In Python, use `api.model(model_id)` for detailed capabilities and `api.pricing(model_id, online_only=False)` for pricing and miner counts. Omit the ID for the full pricing table.

## Python

Supply `KITANI_API_KEY` for inference and `KITANI_FINGERPRINT` for account or billing operations. The SDK reads environment variables or constructor arguments. The CLI profile is private to the CLI.

```python
from kitani import Kitani

with Kitani() as api:
    catalog = api.models()
    model_id = catalog["data"][0]["id"]  # Choose an available model for your request.
    for chunk in api.stream_chat(model_id, [{"role": "user", "content": "Hello"}]):
        for choice in chunk.get("choices", []):
            print(choice["delta"].get("content") or "", end="", flush=True)
```

For headless signup, call `start_signup()`, share only `verification_uri_complete` and `user_code`, then call `poll_signup(device_code)` at the returned interval. Store the approved fingerprint as a secret. Use `create_key(name)` to mint an inference credential and `revoke_key(id)` to retire a CLI-issued key.

```python
from kitani import Kitani

with Kitani() as api:
    request_key = api.new_idempotency_key()
    # Persist request_key with your top-up record before sending the request.
    checkout = api.payment_link("10.00", "paypal", idempotency_key=request_key)
    print(checkout["payment_url"])
    print(api.payment(checkout["id"])["status"])
```

## Crypto checkout

Use `--via tao` or `--via sn132` with `fund link` for Kitani-hosted wallet checkout. The payer connects their extension on the checkout page. To quote and sign in a terminal:

```sh
kitani fund link --usd 10 --via tao --json
kitani fund quote PAYMENT_ID --sender PUBLIC_COLDKEY --json
kitani fund pay PAYMENT_ID --wallet WALLET_NAME
kitani fund status PAYMENT_ID --wait
```

For SN132 ⴵ, supply `--hotkey STAKING_HOTKEY_ADDRESS` to both quote and pay. Use the same sending coldkey for that link. The quote includes the sender-specific invoice, exact amount, estimated TAO fee, recipient, and block expiry. A plain transfer to the recipient lacks the invoice and may never credit the account. See the [agent skill](https://github.com/kitani-inc/kitani-cli/blob/main/skills/kitani/SKILL.md) for limits, unattended signing and interrupted payments.

## Credentials and output

| Credential | Purpose |
| --- | --- |
| Fingerprint | Account and payment management, minting and revoking CLI inference keys |
| Inference key | Authenticated inference against prepaid credit |
| Verification URL and user code | Share with the person authorizing this terminal |
| Payment URL | Share with a payer for one account, amount and payment method |

The CLI stores a plaintext SQLite profile in `~/.config/kitani` with owner-only file permissions on POSIX systems. Use `KITANI_CONFIG_DIR` to isolate runners, and secret injection on shared machines. Environment credentials take precedence. A saved inference key is bound to its profile fingerprint. Use `kitani login --stdin` to import a fingerprint from a pipe. `kitani logout` clears the local profile. Back up a fingerprint-only account before discarding its last credential.

Add `--json` to any command. Results go to stdout, diagnostics to stderr. Exit codes are 0 for completion, 1 for other failures, 2 for invalid syntax, 3 for authentication or permission failures, 4 for insufficient credit, 5 for rate limiting, 6 for a wait timeout, and 130 for interruption. A successful status query can report a failed payment. Inspect the status field before treating the invoice as paid.

## Development

```sh
python -m pip install -e '.[test]'
python -m pytest
```

The canonical agent instructions are in `skills/kitani/SKILL.md`. The website serves a copy at `/agents/skill.md`. Update the mirror when changing the workflow.

## Run and monitor an agent

| Task | Terminal |
| --- | --- |
| Find online models with tool calling | `kitani pricing --online --capability tools --min-context 128000 --sort input-price` |
| Create a budgeted key and inspect spend | `kitani keys create --name worker --budget-usd 5.00`, then `kitani keys list` |
| Rotate a CLI-issued secret, keeping its budget and usage history | `kitani keys rotate KEY_ID --current-fingerprint SHORT_FINGERPRINT` (from `keys list`) |
| Change an existing CLI key’s lifetime ceiling | `kitani keys budget KEY_ID --usd 10.00` (or explicitly pass `--unlimited`) |
| Read seven days of spend | `kitani usage --since 7d --by model --json` or `--by key` |
| Investigate individual requests | `kitani requests --last 10 --key KEY_ID --since 24h --json` |
| Track deposits across the dashboard and CLI | `kitani fund history --json` and `kitani fund status --last --wait` |
| Check which executable and credentials are active | `python -m kitani.cli doctor --json` in the SDK environment |
| Name and manage authorized devices | `kitani signup --name build-runner`, `kitani terminals list`, `kitani terminals revoke ID` |

Pass a complete chat payload with `kitani chat --request-file request.json --json`. Use `--request-file -` to read JSON from stdin. Include the model ID, messages and any model-supported options such as tools, tool choice or response format. A streaming request produces newline-delimited chunk objects, including tool-call deltas. The Python equivalents are `api.chat(model, messages, **options)` and `api.stream_chat(model, messages, **options)`.

For an email-free account, run `kitani recovery add EMAIL` and then `kitani recovery verify` while you still have the fingerprint. If you lose access, open Kitani’s [account recovery page](https://kitani.ai/cli/recover), complete Turnstile and verify the emailed code, then authorize your new terminal against that account. Check other terminals from dashboard settings or with `kitani terminals list`.

## Release to PyPI

1. Sign in to [PyPI Publishing](https://pypi.org/manage/account/publishing/) and add a pending **GitHub** publisher using these exact values.

   | Field | Value |
   | --- | --- |
   | PyPI project name | `kitani` |
   | GitHub owner | `kitani-inc` |
   | Repository | `kitani-cli` |
   | Workflow filename | `release.yml` |
   | Environment | `pypi` |

2. Push the release commit on `main`. In [GitHub Releases](https://github.com/kitani-inc/kitani-cli/releases/new), create the tag matching the version in `pyproject.toml` (currently `v0.2.1`), target that commit, and select **Publish release**. The workflow runs when a release is published.
3. Check the [publishing workflow](https://github.com/kitani-inc/kitani-cli/actions/workflows/release.yml). It runs tests, builds the wheel and source distribution, verifies the tag against the wheel metadata, and publishes with GitHub’s short-lived identity. After it succeeds, verify the version on [PyPI](https://pypi.org/project/kitani/) and try `pipx run --no-cache --spec kitani kitani --version`.
4. For later releases, increment the version in `pyproject.toml`, push the commit, and publish the matching GitHub release. The verified publisher carries over. The README in the tagged commit supplies the PyPI description for that release.
