leaf-router-1 and 25 frontier models, with optional server-side Leaf agronomy tools (weather, soil, imagery, machine).
For conceptual background, routing behavior, system prompt guidance, and the full 26-model catalog, see Leaf Inference Overview.
Base URL
Endpoints
Authentication & CORS
AuthenticatePOST /chat/completions exclusively using Leaf’s V2 Keycloak realm (https://auth.withleaf.io/realms/leaf). Legacy V1 tokens are not accepted, and all built-in leaf_tools calls execute against https://api-v2.withleaf.io:
- Leaf V2 API key (recommended): Create an API key in dashboard.withleaf.io (API Keys → Create API key) and pass
<client_id>:<client_secret>inAuthorization: Bearer <client_id>:<client_secret>(compatible with every OpenAI SDK’sapi_keyoption) orX-API-Key: <client_id>:<client_secret>. Leaf Inference exchanges it with Keycloak (grant_type=client_credentials) and caches the short-lived access token automatically. - Keycloak OAuth2 Bearer token: Pass an
access_tokenobtained fromPOST https://auth.withleaf.io/realms/leaf/protocol/openid-connect/tokeninAuthorization: Bearer <access_token>. Verified cryptographically against Keycloak’s RS256 JWKS (https://auth.withleaf.io/realms/leaf/protocol/openid-connect/certs).
OPTIONS returns 204 No Content):
Access-Control-Allow-Origin: *Access-Control-Allow-Methods: GET, POST, OPTIONSAccess-Control-Allow-Headers: Authorization, Content-Type, X-API-Key, X-Leaf-Tools, X-Leaf-ProjectAccess-Control-Max-Age: 86400
List models
GET/models
Returns the public catalog of models available on Leaf Inference, including context lengths, zero-data-retention flags, Leaf pricing (25% below list), and maker list pricing. No authentication is required; responses are cached with Cache-Control: public, max-age=300.
Request
Response
200 OK
Create chat completion
POST/chat/completions
Creates a model response for the given chat conversation. Supports standard text prompts, caller-supplied system prompts, multimodal images (image_url / input_image), streaming Server-Sent Events, caller-defined function calling (tools), and Leaf’s server-side agronomy data tools (leaf_tools).
Headers
Body parameters
System prompt ordering: When
leaf_tools is enabled, Leaf prepends a system message instructing the model how to use the enabled Leaf data groups (weather, soil, imagery, machine) ahead of your messages array. Your own role: "system" message(s) remain intact after it. See System prompts.Request examples
Non-streaming response
200 OK (Content-Type: application/json, Cache-Control: no-store)
Streaming response (stream: true)
200 OK (Content-Type: text/event-stream; charset=utf-8, Cache-Control: no-store, X-Accel-Buffering: no)
Chunks follow the OpenAI chat.completion.chunk SSE format. When leaf_tools executes server-side, Leaf emits status chunks containing a top-level leaf_tool object before continuing to stream the final assistant text. If stream_options: { "include_usage": true } is set, a final usage chunk (choices: []) is emitted right before data: [DONE].
delta.reasoningis streamed alongsidedelta.contentwhen reasoning text is produced.leaf_tool.statustransitions from"running"(includesarguments) to"done"or"error".- Standard OpenAI SDKs ignore the extra
leaf_toolfield safely while custom UIs can render live tool-call indicators.

