Expand description
§kaeso-kpp
KPP, the Kaeso Provider Protocol: the canonical, stateless in-process representation of model requests, responses, stream events, errors, token counts, embeddings, rerankings, images, speech, transcriptions, video jobs, decisions and model listings that every Kaeso wire format translates through.
This crate holds the KPP types and the rules that need no wire format: validate() checks a request, required_capabilities() says what a model must support to serve it, and ModelList::page pages a model listing. It has no codec logic and no I/O. The codecs that translate every wire format, from Anthropic, OpenAI and Gemini chat to images, audio, video and decisions, into KPP and back are in kaeso-codecs.
[dependencies]
kaeso-kpp = "0.7"use kaeso_kpp::{GenerateRequest, Message, Request, StreamMode, serde_json};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let req = GenerateRequest::new("claude-sonnet-4-6")
.with_system("Answer in one sentence.")
.with_message(Message::user("Hello"))
.with_stream(StreamMode::on(true));
req.validate()?;
assert!(req.required_capabilities().streaming);
let json = serde_json::to_value(Request::Generate(req))?;
assert_eq!(json["generate"]["model"], "claude-sonnet-4-6");
Ok(())
}Both crates are developed in the Kaeso repository. The reference documentation, with every type and every field of every wire format, is at docs.kaeso.app/development/kpp.
License: MIT.
Re-exports§
pub use bytes;pub use indexmap;pub use serde_json;
Structs§
- Answer
- The answer to one question.
- Asset
- An image a decision request references by its key.
- Audio
Block - Audio
Delta - Audio
Header - Audio
Input - Audio a request sends: inline bytes, a URL or a provider file id.
- Audio
Output - Base64
Source - Inline media: its bytes, held once and decoded, and their media type.
- Base64
Text - Media bytes as standard, padded base64, written chunk by chunk.
- Block
Delta - Block
Start - Block
Stop - BoxAnswer
- A box’s edges as fractions of the image’s height (
top,bottom, from the top) and width (left,right, from the left). - BoxQuestion
- A question that locates what its instructions describe in an image.
- Cache
Hint - Cache
Write Breakdown - Capabilities
- Choice
- A question that picks one option.
- Choice
Answer - The chosen option and a probability per option.
- Choice
Option - One option of a choice question.
- Citation
- Count
Tokens Response - Decide
Request - A decision request: typed questions about one input, answered with probabilities instead of generated text.
- Decide
Response - The answers to a decision request, one per question in question order.
- Decision
Cache - How the provider caches a decision request’s prefix (OpenAI’s
prompt_cache_keyandprompt_cache_options). - Dialogue
Line - One line of a dialogue.
- Document
Block - Embed
Request - Embed
Response - Embedding
- Extras
- File
IdSource - Function
Tool - Generate
Request - Generated
Image - One image of a reply: its bytes or a link, and the prompt the provider actually used.
- Image
Block - Image
Event - One event of a streamed image reply: a partial image, or a finished one with its usage.
- Image
Input - An image a request sends: inline bytes, a URL or a provider file id.
- Image
Request - A request for images: generation, edit or variation.
- Image
Response - The reply to an image request.
- Image
Settings - The settings a provider reports it used, for all images of a reply.
- Json
Block - Structured data, written as the app wrote it.
- Json
Schema Spec - KppError
- Level
- One level of a score question.
- Message
- Model
Info - Model
List - Model
Prices - A model’s token prices in USD per million tokens, as decimal strings such as
"3"or"0.075"; a price that isn’t known is absent. - Models
Query - Opaque
- Origin
- Predicate
- A yes/no question, with what counts as yes and as no.
- Predicate
Answer - The probability that the answer to a yes/no question is yes.
- Question
- One question of a decision request.
- RawItem
- RawJson
- RawUsage
- Reasoning
Block - Reasoning
Config - Reasoning
Header - Refusal
- A question the model declined to answer.
- Refusal
Block - Rerank
Document - One document to score: its text, and what else the app sent with it.
- Rerank
Request - A query and the documents a rerank model scores against it.
- Rerank
Response - The documents a rerank model scored, best first.
- Rerank
Result - One scored document: its position in the request, its score as the provider gave it, and the document when the app asked for it.
- Response
- Response
Delta - Response
Start - Response
Stop - Sampling
- Score
- A question that rates on ordered levels.
- Score
Answer - The expected level,
Σ i·p_iover the levels numbered from 0, and a probability per level. - Speech
Alignment - When each character of spoken text starts and ends, in seconds from the start of the audio.
- Speech
Event - One event of streamed audio: a piece of the audio, or the end with its usage.
- Speech
Request - A request for generated audio: speech, a dialogue, a sound effect, music, or speech in another voice.
- Speech
Response - The reply to a request for audio.
- Summary
Delta - Text
Block - Text
Source - Tool
Call Block - Tool
Call Header - Tool
Result Block - Transcript
Event - One event of a streamed transcript: a piece of text, a finished segment, or the end.
- Transcript
Segment - A timed stretch of a transcript.
- Transcript
Word - A timed word of a transcript.
- Transcription
Request - A request to transcribe or translate audio.
- Transcription
Response - The reply to a transcription request.
- Unknown
Dialect - Usage
- Video
Block - Video
Error - Why a video job failed, as the provider says it.
- Video
Image - An image a video request sends, and what it is for.
- Video
Job - A video job as the provider reports it: when it is started, and each time it is asked.
- Video
List - A page of a video listing.
- Video
List Query - What a video listing asks for: a page after an id, its length and its order.
- Video
Output - A file a finished video job made: where to fetch it, and its media type when known.
- Video
Request - A request that starts a video job: a generation or a remix.
Enums§
- Answer
Value - What a question was answered with.
- Audio
Format - Block
- Block
Header - Cache
Ttl - Choice
Value - An option’s value: a key or text, or OpenAI’s
trueandfalse. - Decision
Input - What a decision request’s questions are about.
- Delta
- Description
- What an option, level or answer means: text, or structured data as written.
- Dialect
Id - Embed
Encoding - Embed
Input - Embedding
Vector - Error
Kind - Image
Background - The background of generated images.
- Image
Delivery - Whether a reply carries an image’s bytes or a link to it.
- Image
Format - The file format of generated images.
- Image
Operation - What an image request asks for.
- Image
Quality - How much effort the provider spends on each image.
- Image
Size - An image size:
auto, orWIDTHxHEIGHTin pixels. - Instructions
- What a question asks.
- List
Order - The order of a video listing.
- Modality
- Model
Feature - A request feature a model takes.
- Model
Lifecycle - Opaque
Kind - Output
Spec - Question
Kind - The type of a question and what it chooses from.
- Reasoning
Effort - Reasoning
Mode - Reasoning
Summary - Reply
- Request
- Request
Kind - Retry
- Whether sending the same request again can succeed.
- Role
- Source
- Speech
Operation - What a request for generated audio asks for.
- Stop
Reason - Stream
Event - Stream
Mode - Timestamp
Granularity - How finely a transcript is timed.
- Tool
Choice - ToolDef
- Transcript
Format - The form of a transcript: JSON with the text, plain text, subtitles, or JSON with segments, words or speakers.
- Transcription
Operation - What a transcription request asks for.
- Video
Image Role - What an image given to a video request is for.
- Video
Operation - What a video request asks for.
- Video
Status - How far a video job has come.
- Video
Variant - Which file of a made video an output is.
- Voice
- The voice to speak in: one of the provider’s named voices, or a voice by its id.