fix: support developer and function roles for GPT-5.x compatibility (#23)
authorStefan Gasser <redacted>
Sun, 11 Jan 2026 09:14:06 +0000 (10:14 +0100)
committerGitHub <redacted>
Sun, 11 Jan 2026 09:14:06 +0000 (10:14 +0100)
GPT-5.x models use the 'developer' role instead of 'system' for
instructions. The 'function' role is also added for legacy compatibility.

Fixes #22

src/routes/proxy.test.ts
src/routes/proxy.ts
src/services/llm-client.ts

index 660be971c1f9a4b6e8e8818eb566f94d3ace5d8c..cabdb244205b9d1724f3ab796bf475c18a7df687 100644 (file)
@@ -41,6 +41,24 @@ describe("POST /openai/v1/chat/completions", () => {
 
     expect(res.status).toBe(400);
   });
+
+  test("accepts developer role (GPT-5.x compatibility)", async () => {
+    const res = await app.request("/openai/v1/chat/completions", {
+      method: "POST",
+      body: JSON.stringify({
+        messages: [
+          { role: "developer", content: "You are a helpful assistant" },
+          { role: "user", content: "Hello" },
+        ],
+        model: "gpt-5.2",
+      }),
+      headers: { "Content-Type": "application/json" },
+    });
+
+    // Should not be 400 (validation passed)
+    // Will be 401/502 without API key, but that's fine - we're testing validation
+    expect(res.status).not.toBe(400);
+  });
 });
 
 describe("GET /openai/v1/models", () => {
index c1f6e3e4aa5c77b66ee5d27407257b9be0f97a20..509fc5dbafc46cd2528ed53edb548271dc5d5244 100644 (file)
@@ -30,7 +30,7 @@ const ChatCompletionSchema = z
       .array(
         z
           .object({
-            role: z.enum(["system", "user", "assistant", "tool"]),
+            role: z.enum(["system", "developer", "user", "assistant", "tool", "function"]),
             content: z.union([z.string(), z.array(z.any()), z.null()]).optional(),
           })
           .passthrough(), // Allow additional fields like name, tool_calls, etc.
index 451ccfd3e6931dab9fc890276d68e5d81dac3c5c..b986a14da04b375f86ea1fe09562e7d2da5291d7 100644 (file)
@@ -6,7 +6,7 @@ import type { MessageContent } from "../utils/content";
  * Supports both text-only (content: string) and multimodal (content: array) formats
  */
 export interface ChatMessage {
-  role: "system" | "user" | "assistant";
+  role: "system" | "developer" | "user" | "assistant";
   content: MessageContent;
 }
 
git clone https://git.99rst.org/PROJECT