Guides

Models and keys

Configure the language models that read your documents (Anthropic, OpenAI, Gemini or a local one) and Clef, the cheap first model that skips what isn't a receipt.

Spendyard has no model and no keys of its own. It sends documents to the model providers you configure, with your keys, and to nothing else.

Two models

  • The extractor reads the details: vendor, amounts, card, seats, usage, billing. It’s the one you need.
  • The decider is an optional, much cheaper first model. It answers yes-or-no and multiple-choice questions about a document (is it about money, a receipt or an invoice, paid or due, seats or usage) and stops before the extractor when it’s sure the document isn’t about money. On a mailbox, where most mail isn’t, that’s most of the cost saved. Its answers also go to the extractor as hints.

Without a decider, every document goes to the extractor.

Where settings and keys go

Settings go in ~/.spendyard/config.toml; spendyard config init writes a commented one. Flags win over it for one run:

spendyard read invoice.pdf -e anthropic/claude-opus-5-5 -d clef-flash

Keys never go in the config. They come from the environment, or from .env.local or .env in the current folder, then ~/.spendyard/.env; variables already set win. spendyard config shows the models in effect and which keys it found.

The extractor

Anthropic

The default, with claude-haiku-5-5: cheap enough for every receipt. Claude reads PDFs as they are.

[extractor]
provider = "anthropic"
model    = "claude-haiku-5-5"     # claude-opus-5-5 for hard documents
# effort = "low"
# max_tokens = 16000
export ANTHROPIC_API_KEY=sk-ant-…

Through a Cloudflare AI Gateway: set ANTHROPIC_BASE_URL to the gateway’s Anthropic URL, and CLOUDFLARE_AI_GATEWAY_TOKEN if the gateway asks for one.

OpenAI and Gemini

They have no default model, since models change too often to pick one in code: name it.

[extractor]
provider = "openai"       # or "gemini"
model    = "<model>"
Provider Key
openai OPENAI_API_KEY
gemini GEMINI_API_KEY or GOOGLE_API_KEY

A local model

Any server that speaks OpenAI’s Chat Completions: Ollama, vLLM, LM Studio and others. Nothing leaves your machine.

[extractor]
provider = "openai-compatible"
model    = "qwen3:4b"

[providers.openai-compatible]
base_url = "http://localhost:11434/v1"

OPENAI_COMPATIBLE_API_KEY, if the server wants one. Small local models follow the output’s shape less strictly; what slips through is caught when the reading is checked, and flagged.

Clef, the first model

Clef and Clef-flash are open-weights decision models on Cloudflare Workers AI. A document costs about $0.0001 to decide, and Clef can look at images when a document has no text. Clef-flash is the one we measure Spendyard with and suggest.

Set it up

  1. In your Cloudflare dashboard, note your account ID.
  2. Create an API token with the Workers AI — Read permission.
  3. Give Spendyard both:
export CLOUDFLARE_ACCOUNT_ID=…
export CLOUDFLARE_API_TOKEN=…
  1. Turn it on for every run, in the config:
[decider]
provider  = "clef-flash"
threshold = 0.85

or for one run, with -d clef-flash.

threshold is how sure Clef must be that a document isn’t about money before it’s skipped: 0.85 by default. Higher skips less and sends more to the extractor.

To go through a Cloudflare AI Gateway, set CLOUDFLARE_AI_GATEWAY to the gateway’s name.

See what it decides

spendyard eval decide *.eml -d clef-flash      # only the first model's answers, no extractor
spendyard mailbox scan imap -d clef-flash --dry-run

Other first models

Provider Key
jev TYPESAFE_API_KEY TypeSafe’s JEV. Text only. Codiv’s OpenJev with base_url = "https://api.codiv.ai" under [providers.jev]
systemone Clef and similar models on your own server, through llama.cpp or SGLang
none No first model

Any program as a model

provider = "exec" with a command under [extractor] or [decider] runs that program for each document. It gets the request as JSON on standard input and answers with JSON on standard output.

Choosing, with your own documents

spendyard eval measures model combinations on documents whose answers you’ve checked: accuracy per field, cost and time.

spendyard eval label ./eval                       # draft expected answers, for you to review
spendyard eval run ./eval -d none,clef-flash      # with and without Clef