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): Media is either URL or attachment, not both (#808)
Graham Kingda8133b00392
diff --git a/crates/switchyard-translation/src/codecs/openai_media.rs b/crates/switchyard-translation/src/codecs/openai_media.rsindex 7de098f5d..d869cc0b2 100644--- a/crates/switchyard-translation/src/codecs/openai_media.rs+++ b/crates/switchyard-translation/src/codecs/openai_media.rs@@ -113,6 +113,9 @@ fn raw_file_payload(raw: &Value) -> Option<Map<String, Value>> {if block.get("type").and_then(Value::as_str) == Some("input_file") {let mut payload = block.clone();payload.remove("type");+ if payload.contains_key("file_url") {+ payload.remove("filename");+ }return Some(payload);}if block.get("type").and_then(Value::as_str) != Some("document") {@@ -124,9 +127,6 @@ fn raw_file_payload(raw: &Value) -> Option<Map<String, Value>> {"url" => {let mut payload = Map::new();payload.insert("file_url".into(), source.get("url")?.clone());- if let Some(filename) = filename {- payload.insert("filename".into(), filename.into());- }Some(payload)}"text" => Some(file_data_payload(diff --git a/crates/switchyard-translation/tests/request_translation.rs b/crates/switchyard-translation/tests/request_translation.rsindex 806e21412..af96d4d10 100644--- a/crates/switchyard-translation/tests/request_translation.rs+++ b/crates/switchyard-translation/tests/request_translation.rs@@ -149,7 +149,7 @@ fn request_media_survives_reencoding_or_is_rejected() -> TestResult {let image = json!({"type": "input_image", "file_id": "file_image", "detail": "auto"});let audio =json!({"type": "input_audio", "input_audio": {"data": "UklGRg==", "format": "wav"}});- let file = json!({"type": "input_file", "file_url": "https://example.com/report.pdf", "filename": "report.pdf"});+ let file = json!({"type": "input_file", "file_url": "https://example.com/report.pdf"});let document = json!({"type": "document", "source": {"type": "url", "url": "https://example.com/report.pdf"}, "title": "report.pdf"});let text_file = json!({"type": "input_file", "file_data": "aGVsbG8=", "filename": "notes.txt"});let text_document = json!({"type": "document", "source": {"type": "text", "media_type": "text/plain", "data": "hello"}, "title": "notes.txt"});@@ -184,7 +184,20 @@ fn request_media_survives_reencoding_or_is_rejected() -> TestResult {(Responses, Anthropic, audio, None),(Responses, Responses, file.clone(), Some(file.clone())),(Responses, Chat, file.clone(), None),- (Responses, Anthropic, file.clone(), Some(document.clone())),+ (+ Responses,+ Responses,+ json!({"type": "input_file", "file_url": "https://example.com/report.pdf", "filename": "report.pdf"}),+ Some(file.clone()),+ ),+ (+ Responses,+ Anthropic,+ file.clone(),+ Some(+ json!({"type": "document", "source": {"type": "url", "url": "https://example.com/report.pdf"}}),+ ),+ ),(Anthropic, Chat, document.clone(), None),(Anthropic, Responses, document, Some(file)),(