`AiClient::plan` now works out a `CostEstimate` from the saved model's `pricing` and the request, so an app can show the price beside the disclosure before the person agrees. It reads no key and contacts nothing. `Plan::estimate()` returns it. The rule lives in `craft_ai_core::cost::estimate`: the per-image price times the results asked for. A token price above zero gives `None`, because the reply's token count is unknown before sending. Two stated zero token prices give zero. A missing price or an overflow gives `None`, never a guess. History still records an estimate: the adapter's own figure where it gives one, otherwise the plan's, including on a refusal before the adapter is built. `cost_text` keeps part-cent digits, so 0.039 USD no longer reads 0.03. FLUX.1 Fill [pro] carries $0.05 per image, from BFL's price page (cited in the code). Gemini, FLUX 3 and Seedance stay unpriced: their publishers price by resolution tier or by token.
Adopting the Craft AI layer
You want an AI tool in your app, and you want it to work the way the rest of the suite does: a person sets up a model once, and your tool uses it.
This section is for developers. It covers adding a tool to an app, declaring a new kind of tool, and bringing a service or model that can run one. You do not need to edit this repository, the launcher or anyone else's app.
The idea in one minute
flowchart LR
P[Person] -->|sets up once| L[Launcher or your Preferences]
L -->|writes| S[(Shared store<br/>connections, models,<br/>choices)]
A1[Your app] -->|reads| S
A2[Another app] -->|reads| S
A1 -->|status, plan, start| C[AiClient]
C -->|your adapter| M[Model or service]
Five things, in the order you meet them:
| Word | Meaning |
|---|---|
Tool (a Role) |
A job your app offers, such as "Select subject". It has an id, one capability and the inputs it sends. |
| Connection | A place that can run models: a hosted service, a server on this computer, or the built-in engine. It holds the models it offers. Keys live in the keychain, not here. |
| Binding | The person's choice of connection and model for one tool. A suite default, with an optional override per app. |
Adapter (a Provider) |
The code in your app that talks to a connection. An app that has no adapter for a connection says so plainly. |
| Job | One run. You start it, poll it, and can cancel it. |
Your app owns the interface and the result. The shared layer owns everything between.
| The shared layer does | Your app does |
|---|---|
| Stores connections, models, choices, consent and history | Draws the tool: a prompt bar, a button, a click on the image |
| Reads keys, only at the moment a job starts | Builds the request from its own document |
| Checks the model can take your inputs | Shows the disclosure and asks for consent |
| Refuses to send data without consent | Applies the result, with its own undo |
| Runs and tracks the job | Offers cancel, progress and readable errors |
Pick your path
If you want to suggest a vetted built-in model, connection, engine or workflow, start at Propose an AI integration. This is a developer review path, not the person's custom setup described below.
| I want to... | Read | Time |
|---|---|---|
| Add a tool that already exists (Select subject, Remove objects) to my app | Use AI tools in your app | 30 minutes to a first run |
| Offer a kind of tool the suite does not have yet | Declare a new tool | 15 minutes |
| Make my service, API, server or model runnable by the tools | Bring a service or model | 1 hour for a Provider |
| Check I did it properly before I ship | Checklist | 10 minutes |
| Work out why it says "Unavailable" | Troubleshooting | 5 minutes |
Most people need the first guide and the checklist.
See it run first
Every page here is checked by the compiler. The whole story, with two independent apps and a third one that cannot run the service, is one test:
cargo test -p craft-ai-client --test third_party_adoption -j 8
cargo test -p craft-ai-client --doc -j 8
cargo test -p craft-ai-client --test adopting_app_guide --test adopting_tool_guides --test adopting_drift -j 8
cargo run -p craft-ai-client --example custom_tool -j 8
None of them touches the network or your real connections. They use a temporary folder and a scripted stand-in service. If a page and the code disagree, the code is right and the page has a bug. Please fix the page.
What you get, and what you do not
You get: one place where keys, models and choices live; consent that is scoped to your app, the connection, the destination and the kind of data; a job model that works for a two-second edit and a two-minute video; a log; and shared checks that any adapter can run.
You do not get, today:
- A background service. The runtime is in the app's own process. Your app links
craft-ai-clientand runs its adapters itself. A shared daemon is a separate discussion. - Dynamic code loading. A tool is a declaration, and an adapter is code you compile into your app.
- Automatic model installation. Setting up a model is the launcher's Set up AI window, or your own screen built from the shared pieces, and it always asks first.
- A stable API. The contract is accepted in
craft-libs, but this workspace still carries newer additions that are under review (CORE-SYNC). Pin a revision.
Read STATUS before you rely on a provider. It lists what ran against a scripted server, what ran for real on one machine, and what has not run at all. Your own docs should use the same levels, and never claim more.
Ground rules
These come from the people who use the suite. The checks enforce most of them.
- One model choice, everywhere. Never hard-code a model or an address. Read the binding.
- No silent substitution. If the chosen model cannot run, say so. Do not run a different one.
- Nothing leaves the computer without a yes. The layer enforces consent. Do not route around it.
- Keys never travel. Not through environment variables you set, command lines, logs or errors.
- Plain words. Everything a person reads avoids engine names, hardware words and developer terms.
- Every app works with no AI. An unset tool is greyed out with a reason, never broken.
- Say what you ran. Configured, verified and executable are three different claims.
Where things live
| Folder | What is in it |
|---|---|
crates/ai-core |
The data model and the Provider trait. No I/O. Builds for wasm. |
crates/ai-client |
AiClient, ToolDesk and ProviderFactory. What an app holds. |
crates/ai-features |
The catalogue of tools and how each can be set up. |
crates/ai-native |
The shared store file, key stores, consent and history files. |
crates/ai-egui |
Optional theme-neutral widgets. |
docs/ |
These guides, the layout, the platform contract and custom connections and sources. |
Getting help and giving back
Open an issue on storytold/craft-ai-integrations. Say which guide you followed, which step was
unclear and what you expected. A step that needed something the page did not say is a bug in the
page. Small fixes to these pages are welcome as pull requests. See CONTRIBUTING.