openai.internal.ChatExtraPart

A content part carrying the per-message provider directives authored on `${ai.Role { name: …, metadata: { … } }}`. Chat completions places such directives ON A CONTENT PART (`prompt_cache_breakpoint` for OpenAI, OpenRouter's Anthropic-style `cache_control`), while the authored directive lives on the MESSAGE — so, exactly as the Anthropic client does, the metadata attaches to the message's LAST part and everything up to and including it is the cached prefix.

Reference version

Signature

class openai.internal.ChatExtraPart

A content part carrying the per-message provider directives authored on ${ai.Role { name: …, metadata: { … } }}. Chat completions places such directives ON A CONTENT PART (prompt_cache_breakpoint for OpenAI, OpenRouter's Anthropic-style cache_control), while the authored directive lives on the MESSAGE — so, exactly as the Anthropic client does, the metadata attaches to the message's LAST part and everything up to and including it is the cached prefix.

The keys are forwarded VERBATIM: this file does not maintain an allow-list of which directives an OpenAI-compatible endpoint understands, and "verbatim" includes an explicitly authored null.

Getting that last part right is why to_json PARKS the directives under _chat_directives_key() rather than splatting them onto the part: the body then goes through _chat_prune_nulls, whose job is to drop the CLIENT's unset options, and it would take an authored {"cache_control": null} with them. The parked key is opaque to that pass and _chat_apply_directives splices it back onto the part immediately afterwards, so the key never reaches the wire. (The sibling Responses client gets the same result by applying its directives to the serialized body after its own prune.)

Source:<builtin>/openai/ns_internal/chat.bamlbytes 1068911478

Fields

extra

map<string, baml.json.json>

Implementations

baml.ToJson for openai.internal.ChatExtraPart

Instance methods

function

to_json

(self) -> baml.json.json throws baml.json.SerializationError

Source:<builtin>/openai/ns_internal/chat.bamlbytes 1078311476