Skip to main content

Crate kaeso_kpp

Crate kaeso_kpp 

Source
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.
AudioBlock
AudioDelta
AudioHeader
AudioInput
Audio a request sends: inline bytes, a URL or a provider file id.
AudioOutput
Base64Source
Inline media: its bytes, held once and decoded, and their media type.
Base64Text
Media bytes as standard, padded base64, written chunk by chunk.
BlockDelta
BlockStart
BlockStop
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.
CacheHint
CacheWriteBreakdown
Capabilities
Choice
A question that picks one option.
ChoiceAnswer
The chosen option and a probability per option.
ChoiceOption
One option of a choice question.
Citation
CountTokensResponse
DecideRequest
A decision request: typed questions about one input, answered with probabilities instead of generated text.
DecideResponse
The answers to a decision request, one per question in question order.
DecisionCache
How the provider caches a decision request’s prefix (OpenAI’s prompt_cache_key and prompt_cache_options).
DialogueLine
One line of a dialogue.
DocumentBlock
EmbedRequest
EmbedResponse
Embedding
Extras
FileIdSource
FunctionTool
GenerateRequest
GeneratedImage
One image of a reply: its bytes or a link, and the prompt the provider actually used.
ImageBlock
ImageEvent
One event of a streamed image reply: a partial image, or a finished one with its usage.
ImageInput
An image a request sends: inline bytes, a URL or a provider file id.
ImageRequest
A request for images: generation, edit or variation.
ImageResponse
The reply to an image request.
ImageSettings
The settings a provider reports it used, for all images of a reply.
JsonBlock
Structured data, written as the app wrote it.
JsonSchemaSpec
KppError
Level
One level of a score question.
Message
ModelInfo
ModelList
ModelPrices
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.
ModelsQuery
Opaque
Origin
Predicate
A yes/no question, with what counts as yes and as no.
PredicateAnswer
The probability that the answer to a yes/no question is yes.
Question
One question of a decision request.
RawItem
RawJson
RawUsage
ReasoningBlock
ReasoningConfig
ReasoningHeader
Refusal
A question the model declined to answer.
RefusalBlock
RerankDocument
One document to score: its text, and what else the app sent with it.
RerankRequest
A query and the documents a rerank model scores against it.
RerankResponse
The documents a rerank model scored, best first.
RerankResult
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
ResponseDelta
ResponseStart
ResponseStop
Sampling
Score
A question that rates on ordered levels.
ScoreAnswer
The expected level, Σ i·p_i over the levels numbered from 0, and a probability per level.
SpeechAlignment
When each character of spoken text starts and ends, in seconds from the start of the audio.
SpeechEvent
One event of streamed audio: a piece of the audio, or the end with its usage.
SpeechRequest
A request for generated audio: speech, a dialogue, a sound effect, music, or speech in another voice.
SpeechResponse
The reply to a request for audio.
SummaryDelta
TextBlock
TextSource
ToolCallBlock
ToolCallHeader
ToolResultBlock
TranscriptEvent
One event of a streamed transcript: a piece of text, a finished segment, or the end.
TranscriptSegment
A timed stretch of a transcript.
TranscriptWord
A timed word of a transcript.
TranscriptionRequest
A request to transcribe or translate audio.
TranscriptionResponse
The reply to a transcription request.
UnknownDialect
Usage
VideoBlock
VideoError
Why a video job failed, as the provider says it.
VideoImage
An image a video request sends, and what it is for.
VideoJob
A video job as the provider reports it: when it is started, and each time it is asked.
VideoList
A page of a video listing.
VideoListQuery
What a video listing asks for: a page after an id, its length and its order.
VideoOutput
A file a finished video job made: where to fetch it, and its media type when known.
VideoRequest
A request that starts a video job: a generation or a remix.

Enums§

AnswerValue
What a question was answered with.
AudioFormat
Block
BlockHeader
CacheTtl
ChoiceValue
An option’s value: a key or text, or OpenAI’s true and false.
DecisionInput
What a decision request’s questions are about.
Delta
Description
What an option, level or answer means: text, or structured data as written.
DialectId
EmbedEncoding
EmbedInput
EmbeddingVector
ErrorKind
ImageBackground
The background of generated images.
ImageDelivery
Whether a reply carries an image’s bytes or a link to it.
ImageFormat
The file format of generated images.
ImageOperation
What an image request asks for.
ImageQuality
How much effort the provider spends on each image.
ImageSize
An image size: auto, or WIDTHxHEIGHT in pixels.
Instructions
What a question asks.
ListOrder
The order of a video listing.
Modality
ModelFeature
A request feature a model takes.
ModelLifecycle
OpaqueKind
OutputSpec
QuestionKind
The type of a question and what it chooses from.
ReasoningEffort
ReasoningMode
ReasoningSummary
Reply
Request
RequestKind
Retry
Whether sending the same request again can succeed.
Role
Source
SpeechOperation
What a request for generated audio asks for.
StopReason
StreamEvent
StreamMode
TimestampGranularity
How finely a transcript is timed.
ToolChoice
ToolDef
TranscriptFormat
The form of a transcript: JSON with the text, plain text, subtitles, or JSON with segments, words or speakers.
TranscriptionOperation
What a transcription request asks for.
VideoImageRole
What an image given to a video request is for.
VideoOperation
What a video request asks for.
VideoStatus
How far a video job has come.
VideoVariant
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.

Constants§

HEADER_PREFIX
PCM16_MEDIA_TYPE