Add Copilot-Vision-Request header for image requests

fixes #222
This commit is contained in:
Mario Zechner 2025-12-19 05:12:40 +01:00
parent 575dcb2676
commit 0dbc1065ad
3 changed files with 30 additions and 0 deletions

View file

@ -12,6 +12,8 @@
- **Google baseUrl configuration**: Google provider now respects `baseUrl` configuration for custom endpoints or API proxies. ([#216](https://github.com/badlogic/pi-mono/issues/216), [#221](https://github.com/badlogic/pi-mono/pull/221) by [@theBucky](https://github.com/theBucky))
- **GitHub Copilot vision requests**: Added `Copilot-Vision-Request` header when sending images to GitHub Copilot models. ([#222](https://github.com/badlogic/pi-mono/issues/222))
## [0.22.3] - 2025-12-16
### Added

View file

@ -309,6 +309,20 @@ function createClient(model: Model<"openai-completions">, context: Context, apiK
const isAgentCall = lastMessage ? lastMessage.role !== "user" : false;
headers["X-Initiator"] = isAgentCall ? "agent" : "user";
headers["Openai-Intent"] = "conversation-edits";
// Copilot requires this header when sending images
const hasImages = messages.some((msg) => {
if (msg.role === "user" && Array.isArray(msg.content)) {
return msg.content.some((c) => c.type === "image");
}
if (msg.role === "toolResult" && Array.isArray(msg.content)) {
return msg.content.some((c) => c.type === "image");
}
return false;
});
if (hasImages) {
headers["Copilot-Vision-Request"] = "true";
}
}
return new OpenAI({

View file

@ -317,6 +317,20 @@ function createClient(model: Model<"openai-responses">, context: Context, apiKey
const isAgentCall = lastMessage ? lastMessage.role !== "user" : false;
headers["X-Initiator"] = isAgentCall ? "agent" : "user";
headers["Openai-Intent"] = "conversation-edits";
// Copilot requires this header when sending images
const hasImages = messages.some((msg) => {
if (msg.role === "user" && Array.isArray(msg.content)) {
return msg.content.some((c) => c.type === "image");
}
if (msg.role === "toolResult" && Array.isArray(msg.content)) {
return msg.content.some((c) => c.type === "image");
}
return false;
});
if (hasImages) {
headers["Copilot-Vision-Request"] = "true";
}
}
return new OpenAI({