Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

fix(translation): report cache writes in Chat Completions as cache_write_tokens (#947)

Elyas Mehtabuddin657870f321d8
diff --git a/crates/switchyard-translation/src/codecs/openai_chat/buffered.rs b/crates/switchyard-translation/src/codecs/openai_chat/buffered.rs
index 970fbce44..7597e6c3e 100644
--- a/crates/switchyard-translation/src/codecs/openai_chat/buffered.rs
+++ b/crates/switchyard-translation/src/codecs/openai_chat/buffered.rs
@@ -1294,7 +1294,7 @@ pub(crate) fn encode_openai_usage(usage: &Usage) -> Value {
if usage.cached_input_tokens().is_some() || usage.cache_creation_input_tokens().is_some() {
value["prompt_tokens_details"] = json!({
"cached_tokens": usage.cached_input_tokens().unwrap_or(0),
- "cache_creation_tokens": usage.cache_creation_input_tokens().unwrap_or(0),
+ "cache_write_tokens": usage.cache_creation_input_tokens().unwrap_or(0),
});
}
if let Some(reasoning_tokens) = usage.reasoning_tokens {
diff --git a/crates/switchyard-translation/tests/response_translation.rs b/crates/switchyard-translation/tests/response_translation.rs
index cef7155dd..7d3ce5df5 100644
--- a/crates/switchyard-translation/tests/response_translation.rs
+++ b/crates/switchyard-translation/tests/response_translation.rs
@@ -377,7 +377,7 @@ fn responses_reasoning_usage_translates_to_openai_chat_usage_details() -> TestRe
json!({"reasoning_tokens": 3})
);
assert_eq!(
- output["usage"]["prompt_tokens_details"]["cache_creation_tokens"],
+ output["usage"]["prompt_tokens_details"]["cache_write_tokens"],
2
);
let decoded = engine