> ## Documentation Index
> Fetch the complete documentation index at: https://docs.withleaf.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Leaf Inference

> Use Leaf's OpenAI-compatible Inference API and Leaf Router 1 to run frontier agronomy models at 25% off list price with built-in farm data tools.

Leaf Inference is an OpenAI-compatible chat completions API built for agricultural software and agents. Point any OpenAI SDK or HTTP client at `https://withleaf.io/inference/v1`, authenticate with a Leaf V2 API key from [dashboard.withleaf.io](https://dashboard.withleaf.io) (or a Keycloak OAuth2 access token), and call **Leaf Router 1** or any of 25 frontier open-weight and closed models at **25% below maker list price** — with zero data retention and optional live access to Leaf soil, weather, satellite imagery, and machine data.

You can also try models and live tools in the interactive playground at [withleaf.io/inference](https://withleaf.io/inference).

## Base URL and endpoints

```
https://withleaf.io/inference/v1
```

| Method | Path | Auth | Description |
| - | - | - | - |
| GET | `/models` | Public | List available models, context windows, ZDR flags, and Leaf vs. list pricing. |
| POST | `/chat/completions` | Leaf V2 API key or Bearer token | Create a chat completion (streaming or non-streaming), with optional `leaf_tools` and custom function calling. |

For full request/response schemas, streaming SSE chunk formats, and error codes, see the [Inference API Reference](https://docs.withleaf.io/api-reference/inference.md).

***

## Quickstart

Create an API key in [dashboard.withleaf.io](https://dashboard.withleaf.io) (**API Keys → Create API key**) to get a `client_id` (starting with `leaf-api-`) and `client_secret`, then set `LEAF_API_KEY="<client_id>:<client_secret>"`. Point any OpenAI-compatible SDK at `https://withleaf.io/inference/v1` and set `model` to `leaf-router-1` to automatically route every agronomy question to the best zero-data-retention model.

```bash cURL theme={null}
curl https://withleaf.io/inference/v1/chat/completions \
  -H "Authorization: Bearer $LEAF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "leaf-router-1",
    "leaf_tools": ["soil", "weather"],
    "messages": [
      {
        "role": "system",
        "content": "You are a practical agronomy advisor. Give concise, field-ready recommendations and cite units."
      },
      {
        "role": "user",
        "content": "Is the soil near Ames, Iowa warm enough for fall anhydrous this week?"
      }
    ]
  }'
```

```python Python theme={null}
import os
from openai import OpenAI

# LEAF_API_KEY = "<client_id>:<client_secret>" from dashboard.withleaf.io -> API Keys
# (or a Keycloak OAuth2 access_token from auth.withleaf.io)
client = OpenAI(
    base_url="https://withleaf.io/inference/v1",
    api_key=os.environ["LEAF_API_KEY"],
)

reply = client.chat.completions.create(
    model="leaf-router-1",
    messages=[
        {
            "role": "system",
            "content": "You are a practical agronomy advisor. Give concise, field-ready recommendations and cite units.",
        },
        {
            "role": "user",
            "content": "Is the soil near Ames, Iowa warm enough for fall anhydrous this week?",
        },
    ],
    extra_body={"leaf_tools": ["soil", "weather"]},
)
print(reply.choices[0].message.content)
```

```javascript JavaScript theme={null}
import OpenAI from 'openai';

// LEAF_API_KEY = "<client_id>:<client_secret>" from dashboard.withleaf.io -> API Keys
const client = new OpenAI({
  baseURL: 'https://withleaf.io/inference/v1',
  apiKey: process.env.LEAF_API_KEY,
});

const stream = await client.chat.completions.create({
  model: 'leaf-router-1',
  stream: true,
  stream_options: { include_usage: true },
  leaf_tools: ['machine', 'imagery'],
  messages: [
    {
      role: 'system',
      content: 'You are an agronomy assistant helping growers review field operations and satellite imagery.',
    },
    {
      role: 'user',
      content: 'What did we plant on North 80, and how does the latest NDVI look?',
    },
  ],
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
```

***

## Authentication

Leaf Inference authenticates callers **exclusively** against Leaf's **V2 Keycloak realm** (`https://auth.withleaf.io/realms/leaf`) and routes all built-in Leaf data tool calls to **`https://api-v2.withleaf.io`**. Legacy V1 tokens are not accepted. Two V2 credential formats are supported:

### Option 1: Leaf API key (recommended for OpenAI SDKs)

1. Open [dashboard.withleaf.io](https://dashboard.withleaf.io), select your project, and open **API Keys → Create API key**.
2. Copy the generated `client_id` (`leaf-api-...`) and `client_secret` (shown once).
3. Pass `<client_id>:<client_secret>` directly as your `api_key` in any OpenAI SDK (`Authorization: Bearer <client_id>:<client_secret>`) or in the `X-API-Key` header:

```
Authorization: Bearer <client_id>:<client_secret>
```

Leaf Inference automatically exchanges the credentials against Keycloak (`POST https://auth.withleaf.io/realms/leaf/protocol/openid-connect/token` with `grant_type=client_credentials`), caches the short-lived OAuth2 access token until 30 seconds before expiry, and uses it for any `leaf_tools` calls against `https://api-v2.withleaf.io` — so you do not need to manage 5-minute token refreshes in your application.

### Option 2: Keycloak OAuth2 access token

If your service already obtains OAuth2 tokens from `POST https://auth.withleaf.io/realms/leaf/protocol/openid-connect/token` (`client_credentials`, `password`, or `refresh_token` grants — see [Authentication](https://docs.withleaf.io/getting-started/authentication.md)), pass the `access_token` directly:

```
Authorization: Bearer <KEYCLOAK_ACCESS_TOKEN>
```

Leaf Inference verifies the RS256 JWT signature cryptographically against Keycloak's JWKS endpoint (`https://auth.withleaf.io/realms/leaf/protocol/openid-connect/certs`), checks token expiry, and forwards the token to `https://api-v2.withleaf.io` when `leaf_tools` is enabled.

### Multi-project API keys (`X-Leaf-Project`)

If you created a multi-project API key in the dashboard (**Selected projects** or **All my projects**), pass the optional `X-Leaf-Project: <api_owner_username>` header to target a specific project for `leaf_tools` calls on `https://api-v2.withleaf.io`.

* `GET /inference/v1/models` is public and does not require authentication.
* When `leaf_tools` is enabled, the model can only access growers, fields, satellite monitoring, weather, and machine operations authorized for your API key or token (including read-only and project scope restrictions).
* The interactive web playground at [withleaf.io/inference](https://withleaf.io/inference) allows keyless same-origin requests with tighter limits (6 requests/minute, point-based soil and weather tools only, no custom `tools`). External API callers must always authenticate.

***

## Leaf Router (`leaf-router-1`)

`leaf-router-1` is Leaf's agronomy-tuned automatic router. It scores **82.9% overall** on Agronomy Benchmark v3 (data from [Agronomy Arena](https://agronomyarena.com/benchmark)) at **\$2.52 per 1,000 benchmark answers** — beating every individual frontier model on accuracy while cutting per-answer cost by up to 20x compared to leading reasoning models.

### How routing works

On each request with `model: "leaf-router-1"`, Leaf inspects recent conversation context before dispatching the completion:

* **Context inspected**: Up to the last **4** `user` and `assistant` turns (up to **2,400 characters** per message). Caller `system` prompts are forwarded intact to the selected model without distorting routing classification.
* **Multimodal vision routing**: When the conversation includes images (`image_url` or `input_image` content parts), Leaf inspects up to the **3** most recent images alongside the text to classify agricultural subjects (plant disease/lesions, weed species, insect/arthropod pests, or general field photos) and visual difficulty.
* **Task and difficulty classification**: For text requests, Leaf detects task structure (including explicit multiple-choice options such as `A) / B) / C)`), classifies whether the prompt involves general agronomy, EPA pesticide label specifications, or quantitative university extension thresholds, identifies the agronomic domain (crop, nutrient, pest, soil/water, or grower operations), and estimates difficulty.
* **Zero data retention and failover**: Both the routing step and the selected model strictly enforce zero data retention (`zero_data_retention: true`) and deny provider data collection. If classification times out (`3.5s` timeout) or an upstream provider is unavailable, Leaf falls back automatically so requests complete reliably.
* **Opaque response contract**: Responses always return `"model": "leaf-router-1"`. Resolved internal routing targets are never exposed in responses, headers, or errors.

> [!NOTE]
>
> `leaf-quality-router-1` is accepted as an alias for `leaf-router-1`. Use `leaf-router-1` in new integrations.

***

## System prompts

Leaf Inference supports both **caller-supplied system prompts** and **automatic tool system prompts** when Leaf data tools are enabled.

### Caller-supplied system prompts

Include one or more messages with `"role": "system"` inside `messages`, following the standard OpenAI Chat Completions format:

```json theme={null}
{
  "model": "leaf-router-1",
  "messages": [
    {
      "role": "system",
      "content": "You are a certified crop advisor. Answer in imperial units, cite applicable EPA label or university extension assumptions, and ask clarifying questions if growth stage or state is missing."
    },
    {
      "role": "user",
      "content": "What soil temperature should I wait for before applying fall anhydrous ammonia in central Iowa?"
    }
  ]
}
```

* Your `system` messages are passed through verbatim to the model.
* When using `leaf-router-1`, routing classification reads only `user` and `assistant` turns, so detailed persona, formatting, or compliance instructions in your `system` prompt do not interfere with model selection.

### Automatic system prompt when `leaf_tools` is enabled

When you enable one or more groups via `leaf_tools` or `X-Leaf-Tools`, Leaf **prepends** a concise system instruction ahead of your `messages` array. Your own `system` message(s) remain intact right after it.

Specifically, Leaf's prepended system prompt instructs the model to:

1. Use the enabled Leaf data tools (`weather`, `soil`, `imagery`, `machine`) whenever a question requires live agricultural data.
2. Cite the exact dates, locations/coordinates, and units returned by the tools, and state plainly when data is missing or unavailable.
3. For authenticated requests, discover account fields first with `leaf_list_fields` (and `leaf_list_growers` if needed) before calling field-scoped tools.
4. Respect which Leaf data groups are switched off for the current request instead of fabricating unavailable data.

> [!TIP]
>
> Because Leaf prepends its tool-usage instructions automatically, your own `system` prompt does not need to enumerate Leaf's tool schemas. Focus your `system` prompt on persona, regional agronomic standards, output formatting, unit preferences (for example, `"Always answer in imperial units"`), and safety guardrails.

### Recommended system prompt patterns

> [tab] Agronomy advisor
>
> ```text theme={null}
> You are an agronomy assistant for commercial growers and crop advisors.
> Use imperial units (acres, °F, inches, bu/ac) unless the user asks for metric.
> When calling Leaf weather or soil tools, state the location, date range, and soil depth you checked.
> If local crop stage, hybrid, or state extension guidelines affect the recommendation, state your assumptions clearly.
> ```

> [tab] Label & compliance
>
> ```text theme={null}
> You are a crop protection reference assistant.
> Never guess a pre-harvest interval (PHI), re-entry interval (REI), buffer zone, or maximum application rate.
> Always remind the user to verify the exact EPA registration number and state-specific product label before spraying.
> ```

> [tab] Structured extraction
>
> ```text theme={null}
> Extract field scouting observations into valid JSON matching the requested schema.
> Do not invent measurements, pest counts, or dates not present in the user message or attached photo.
> Use null for unknown fields.
> ```

***

## Supported parameters and default values

The table below lists every request body parameter and header supported by `POST /inference/v1/chat/completions`, along with its default value and server-side bounds.

### Request body parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `model` | string | **Required** | Model ID from `GET /inference/v1/models` (for example, `leaf-router-1`, `gpt-6.2-astra`, `gemini-4-carbon`, `kimi-k3.1`). |
| `messages` | array | **Required** | Non-empty array of message objects (`system`, `user`, `assistant`, `tool`). Supports plain text and multimodal content arrays (`text`, `image_url`, `input_image`). |
| `max_tokens` | integer | `8192` | Maximum completion tokens. Clamped to `1`–`32768` for authenticated API requests (`1`–`8192` in the public playground). |
| `max_completion_tokens` | integer | `8192` | OpenAI-compatible alias for `max_tokens`. If both are provided, `max_completion_tokens` takes precedence. Same `1`–`32768` clamp. |
| `stream` | boolean | `false` | When `true`, streams Server-Sent Events (`text/event-stream`) ending in `data: [DONE]`. |
| `stream_options` | object | `{ "include_usage": false }` | Streaming options. Set `{ "include_usage": true }` with `stream: true` to emit a final usage-only chunk before `data: [DONE]`. |
| `leaf_tools` | boolean \| string \| string\[] | Disabled | Enables Leaf's server-side agronomy data tools. Accepts `true`, `"all"`/`"on"`/`"yes"`/`"1"`, a comma-separated string (`"weather,soil"`), or an array (`["weather", "soil", "imagery", "machine"]`). Overrides `X-Leaf-Tools`. |
| `tools` | array | Omitted | Caller-defined OpenAI function-calling tool definitions. Can be combined with `leaf_tools` (names starting with `leaf_` that match built-in Leaf tools are reserved). Stripped in the anonymous playground. |
| `tool_choice` | string \| object | Model default | Controls tool selection (`"auto"`, `"none"`, `"required"`, or a specific function object). Stripped in the anonymous playground. |
| `parallel_tool_calls` | boolean | Model default | Whether the model may emit multiple tool calls in a single turn. |
| `temperature` | number | Model default | Sampling temperature. Higher values increase randomness; lower values make output more deterministic. |
| `top_p` | number | Model default | Nucleus sampling probability mass cutoff. |
| `top_k` | integer | Model default | Limits token sampling to the top `k` candidates (on models that support `top_k`). |
| `stop` | string \| string\[] | Omitted | Up to one or more stop sequences where generation halts. |
| `seed` | integer | Omitted | Best-effort deterministic sampling seed (where supported by the model). |
| `presence_penalty` | number | Model default | Penalizes tokens that have already appeared in the text (`-2.0` to `2.0`). |
| `frequency_penalty` | number | Model default | Penalizes tokens proportionally to how often they have appeared (`-2.0` to `2.0`). |
| `repetition_penalty` | number | Model default | Multiplicative penalty against repeated tokens (where supported by the model). |
| `response_format` | object | Omitted | Constrains output structure, such as `{ "type": "json_object" }` or `{ "type": "json_schema", "json_schema": { ... } }` on supporting models. |
| `logit_bias` | object | Omitted | Map of token IDs to bias values (`-100` to `100`) on supporting models. |
| `logprobs` | boolean | Model default (`false`) | Whether to return log probabilities of output tokens (where supported). |
| `top_logprobs` | integer | Omitted | Number of most-likely tokens to return per position when `logprobs` is `true`. |
| `reasoning` | object | Model default (playground: `{ "effort": "low" }`) | Controls reasoning behavior on reasoning-capable models (for example, `{ "effort": "low" }`, `"medium"`, or `"high"`). Authenticated API calls use each model's default unless specified. |
| `reasoning_effort` | string | Model default | Shorthand string for reasoning effort (`"low"`, `"medium"`, `"high"`) on supporting models. |

### Request headers

| Header | Required | Default | Description |
| - | - | - | - |
| `Authorization` | Yes (or `X-API-Key`) | — | `Bearer <client_id>:<client_secret>` (Leaf V2 API key from [dashboard.withleaf.io](https://dashboard.withleaf.io)) or `Bearer <KEYCLOAK_ACCESS_TOKEN>` from `auth.withleaf.io`. |
| `X-API-Key` | No | — | Alternative to `Authorization` for passing `<client_id>:<client_secret>` directly (ignored if `Authorization: Bearer` is present). |
| `Content-Type` | Yes (`POST`) | — | Must be `application/json`. |
| `X-Leaf-Tools` | No | Disabled | Alternative to the `leaf_tools` body field. Accepts `on`, `all`, `true`, `1`, `yes`, or a comma-separated list such as `weather,soil`. Ignored if `leaf_tools` is present in the JSON body. |
| `X-Leaf-Project` | No | Key default project | Optional API owner username for multi-project V2 API keys (`selected` or `all` project scope). Forwarded to `https://api-v2.withleaf.io` on `leaf_tools` calls. |

> [!NOTE]
>
> **Server-enforced parameters**: Only the parameters listed above are forwarded to models. Unrecognized fields and provider-routing overrides are stripped server-side so Leaf always enforces zero data retention, privacy controls, and automatic failover. Usage accounting is always requested so `usage` totals are populated.

***

## Built-in Leaf agronomy tools (`leaf_tools`)

Switch on live agricultural data per request with `"leaf_tools"` in the JSON body (OpenAI Python SDK: `extra_body={"leaf_tools": [...]}`) or with the `X-Leaf-Tools` header.

### Tool groups

| Group | Data provided | Scope |
| - | - | - |
| `weather` | Daily and hourly weather forecasts (default 7 days) and historical weather for coordinates or Leaf fields. | Point & account |
| `soil` | Hourly soil temperature and volumetric soil moisture across 5 depth layers (`0–1`, `1–3`, `3–9`, `9–27`, `27–81 cm`). | Point & account |
| `imagery` | Monitored satellite fields (Sentinel, Planet) and image availability metadata (date, cloud %, coverage, RGB/NDVI). | Account only |
| `machine` | Field operations (`planted`, `applied`, `harvested`, `tillage`) and operation summaries (area, rate, yield, moisture, product, variety). | Account only |

Enable all four groups at once with `"leaf_tools": true` or `X-Leaf-Tools: all`. Whenever any group is enabled on an authenticated request, Leaf also includes `leaf_list_growers` and `leaf_list_fields` automatically so the model can resolve grower and field names to IDs.

### Available server-side tools

| Tool name | Group | Parameters | Notes & defaults |
| - | - | - | - |
| `leaf_list_growers` | Auto (signed in) | `page` (int ≥ 0, default `0`) | Lists up to 50 Leaf users per page (`id`, `name`, `createdTime`). |
| `leaf_list_fields` | Auto (signed in) | `leaf_user_id` (optional), `page` (int ≥ 0, default `0`) | Lists up to 50 fields per page (`id`, `name`, `leafUserId`, `area`, `farmId`, `providerName`, `createdTime`). |
| `leaf_weather_forecast` | `weather` | `lat`, `lon`, `granularity` (`daily` \| `hourly`), `units` (`metric` default \| `imperial`) | Point forecast; defaults to the next 7 days. |
| `leaf_weather_history` | `weather` | `lat`, `lon`, `granularity`, `start_date`, `end_date` (`YYYY-MM-DD`), `units` (`metric` default) | Observed history; up to 366 days (`daily`) or 30 days (`hourly`). |
| `leaf_field_weather` | `weather` | `leaf_user_id`, `field_id`, `kind` (`forecast` \| `history`), `granularity`, `start_date`, `end_date`, `units` (`metric` default) | Uses the field boundary centroid. `start_date`/`end_date` required for `history`. |
| `leaf_soil_conditions` | `soil` | `kind` (`forecast` \| `history`), `lat` + `lon` **or** `leaf_user_id` + `field_id`, `start_date`, `end_date`, `units` (`metric` default) | Always hourly. Forecasts use the ICON model (7 days); observed history covers up to 30 days and lags a few days behind today. |
| `leaf_list_satellite_fields` | `imagery` | `page` (int ≥ 0, default `0`) | Lists up to 50 satellite-monitored fields (`id`, `externalId`, `providers`, `createdAt`, `startDate`, `endDate`). |
| `leaf_field_imagery` | `imagery` | `satellite_field_id`, `start_date`, `end_date`, `max_clouds` (`0`–`100`) | Returns up to 30 processes with dates, cloud cover, coverage, provider, status, and available image types/resolutions. Signed download URLs are withheld from model context. |
| `leaf_list_operations` | `machine` | `leaf_user_id`, `field_id`, `operation_type` (`planted` \| `applied` \| `harvested` \| `tillage`), `start_date`, `end_date`, `page` (default `0`) | Returns up to 30 operations per page, sorted newest first. |
| `leaf_operation_summary` | `machine` | `operation_id` | Returns summary totals and averages (geometry omitted). |

### Execution behavior and combining with your own `tools`

* **Server-side execution loop**: Leaf executes built-in tool calls server-side for up to **6 rounds** per completion and merges token `usage` across rounds.
* **Compaction and truncation**: Weather and soil responses are compacted into columnar arrays; hourly series longer than 72 hours (3 days) are thinned to every 3 hours (`"resolution": "every 3 hours"`). Individual tool outputs are capped at **30,000 characters**.
* **Transparency in responses**:
  * **Non-streaming**: Responses include a top-level `leaf_tool_calls` array (`[{ "name", "arguments" }]`) whenever one or more Leaf tools ran.
  * **Streaming**: Leaf emits progress chunks carrying `leaf_tool` metadata (`status: "running"`, then `"done"` or `"error"`) alongside standard OpenAI delta chunks.
* **Mixing with custom caller `tools`**: You can send your own OpenAI `tools` alongside `leaf_tools`. Built-in `leaf_*` tool names are reserved when `leaf_tools` is enabled. If a model emits any caller-defined tool call in a turn, Leaf returns your `tool_calls` immediately with `finish_reason: "tool_calls"` so your application stays in control (any Leaf calls emitted in the same turn are dropped).

***

## Available models and pricing

Every model in Leaf Inference is served at **25% below its maker's list price**. Query `GET https://withleaf.io/inference/v1/models` programmatically for the live catalog and pricing.

| Model ID | Name | Maker | Type | Context | ZDR | Leaf price (in / out per 1M) | List price (in / out per 1M) |
| - | - | - | - | - | - | - | - |
| `leaf-router-1` | Leaf Router 1 | Leaf | Router | 1M | Yes | $1.45 / $10.67 | $1.93 / $14.22 |
| `gpt-6.2-astra` | GPT-6.2 Astra | OpenAI | Closed | 1M | Yes | $6.00 / $30.00 | $8.00 / $40.00 |
| `gpt-6.2-astra-pro` | GPT-6.2 Astra Pro | OpenAI | Closed | 1M | Yes | $6.00 / $30.00 | $8.00 / $40.00 |
| `gemini-4-carbon` | Gemini 4 Carbon | Google | Closed | 1M | Yes | $3.00 / $15.00 | $4.00 / $20.00 |
| `claude-fable-5.2` | Claude Fable 5.2 | Anthropic | Closed | 1M | No | $6.00 / $30.00 | $8.00 / $40.00 |
| `gemini-4-neon` | Gemini 4 Neon | Google | Closed | 1M | Yes | $2.25 / $11.25 | $3.00 / $15.00 |
| `gpt-6.2-sol-pro` | GPT-6.2 Sol Pro | OpenAI | Closed | 1M | Yes | $1.50 / $7.50 | $2.00 / $10.00 |
| `gpt-6.2-sol` | GPT-6.2 Sol | OpenAI | Closed | 1M | Yes | $1.50 / $7.50 | $2.00 / $10.00 |
| `gpt-6-astra` | GPT-6 Astra | OpenAI | Closed | 1M | Yes | $7.50 / $37.50 | $10.00 / $50.00 |
| `gemini-4-argon` | Gemini 4 Argon | Google | Closed | 1M | Yes | $3.00 / $15.00 | $4.00 / $20.00 |
| `gemini-3.8-flash` | Gemini 3.8 Flash | Google | Closed | 1M | Yes | $0.62 / $3.09 | $0.83 / $4.12 |
| `gpt-6.1-sol` | GPT-6.1 Sol | OpenAI | Closed | 1M | Yes | $1.50 / $7.50 | $2.00 / $10.00 |
| `gemini-4-hydrogen` | Gemini 4 Hydrogen | Google | Closed | 1M | Yes | $1.13 / $5.63 | $1.50 / $7.50 |
| `gemini-3.1-pro` | Gemini 3.1 Pro | Google | Closed | 1M | Yes | $1.50 / $9.00 | $2.00 / $12.00 |
| `gemini-3.5-flash` | Gemini 3.5 Flash | Google | Closed | 1M | Yes | $1.13 / $6.75 | $1.50 / $9.00 |
| `gemini-3-flash` | Gemini 3 Flash | Google | Closed | 1M | Yes | $0.38 / $2.25 | $0.50 / $3.00 |
| `kimi-k3.1` | Kimi K3.1 Pro | Moonshot AI | Open weights | 1M | Yes | $0.19 / $6.60 | $0.25 / $8.80 |
| `claude-opus-5.5` | Claude Opus 5.5 | Anthropic | Closed | 1M | Yes | $3.00 / $15.00 | $4.00 / $20.00 |
| `grok-4.7` | Grok 4.7 | xAI | Closed | 500K | Yes | $1.50 / $4.50 | $2.00 / $6.00 |
| `muse-spark-open` | Muse Spark Open | Meta | Open weights | 1M | Yes | $0.94 / $3.19 | $1.25 / $4.25 |
| `qwen4-max` | Qwen4 Max | Qwen | Closed | 1M | No | $1.07 / $3.20 | $1.42 / $4.27 |
| `kimi-k3` | Kimi K3 | Moonshot AI | Open weights | 1M | Yes | $0.14 / $12.00 | $0.19 / $16.00 |
| `grok-4.3` | Grok 4.3 | xAI | Closed | 1M | Yes | $0.94 / $1.88 | $1.25 / $2.50 |
| `deepseek-v4.1-flash` | DeepSeek V4.1 Flash | DeepSeek | Open weights | 1M | Yes | $0.02 / $0.15 | $0.02 / $0.20 |
| `claude-sonnet-5.5` | Claude Sonnet 5.5 | Anthropic | Closed | 1M | Yes | $1.50 / $7.50 | $2.00 / $10.00 |
| `gpt-6-luna` | GPT-6 Luna | OpenAI | Closed | 1M | Yes | $0.08 / $0.38 | $0.10 / $0.50 |

***

## Privacy, zero data retention, and limits

* **Zero data retention (ZDR)**: 24 of 26 catalog models — including `leaf-router-1` — pin every request strictly to zero-data-retention endpoints (`zero_data_retention: true`). All 26 models prohibit provider data collection and training, and Leaf never logs prompts or outputs.
* **Anonymous user hashing**: Leaf passes only a one-way SHA-256 account hash for abuse prevention, never raw grower emails or account IDs.

### Rate and payload limits

| Limit | Authenticated API | Public playground (`withleaf.io/inference`) |
| - | - | - |
| Rate limit | 60 requests / minute per account | 6 requests / minute per IP |
| Max request body | 2 MB | 2 MB |
| Max conversation length | Model context window | Last 12 messages, 16,000 characters max |
| Default `max_tokens` | `8192` | `8192` |
| Max `max_tokens` / `max_completion_tokens` | `32768` | `8192` |
| Default `reasoning` | Model default | `{ "effort": "low" }` |
| Leaf data tools | `weather`, `soil`, `imagery`, `machine` + account growers/fields | Point-based `weather` and `soil` only |
| Custom caller `tools` | Supported | Disabled |
| Max server-side Leaf tool rounds | 6 per request | 6 per request |
| Max Leaf tool result size | 30,000 characters per tool call | 30,000 characters per tool call |

## What to do next

* [Inference API Reference](https://docs.withleaf.io/api-reference/inference.md) — Full endpoint reference, streaming SSE event formats, response schemas, and error codes.
* [Authentication](https://docs.withleaf.io/getting-started/authentication.md) — Obtain your Leaf Bearer token.
* [Weather Overview](https://docs.withleaf.io/weather/overview.md) — Details on weather models, soil moisture depth layers, and unit systems.
* [MCP Server](https://docs.withleaf.io/mcp/overview.md) — Connect Leaf directly to Cursor, Claude Code, and other MCP clients.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.