Skip to content

Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy

Rust

tighten responses request schema

Raine Virtac0a23621b1ef
diff --git a/src/translate/request.test.ts b/src/translate/request.test.ts
index c1d43f2..43af7af 100644
--- a/src/translate/request.test.ts
+++ b/src/translate/request.test.ts
@@ -2,12 +2,12 @@ import { describe, expect, it } from "bun:test"
import type { AnthropicRequest } from "../anthropic/schema.ts"
import { translateRequest } from "./request.ts"
-describe("translateRequest", () => {
- const baseRequest: AnthropicRequest = {
- model: "claude-sonnet-4-6",
- messages: [{ role: "user", content: "hello" }],
- }
+const baseRequest: AnthropicRequest = {
+ model: "claude-sonnet-4-6",
+ messages: [{ role: "user", content: "hello" }],
+}
+describe("translateRequest", () => {
it("omits reasoning include when reasoning is not enabled", () => {
const translated = translateRequest(baseRequest)
@@ -24,4 +24,49 @@ describe("translateRequest", () => {
expect(translated.reasoning).toEqual({ effort: "medium" })
expect(translated.include).toEqual(["reasoning.encrypted_content"])
})
+
+ it("returns only the expected top-level upstream request fields", () => {
+ const translated = translateRequest({
+ ...baseRequest,
+ system: "follow instructions",
+ tools: [
+ {
+ name: "lookup_weather",
+ description: "Look up the weather",
+ input_schema: {
+ type: "object",
+ properties: { city: { type: "string" } },
+ required: ["city"],
+ },
+ },
+ ],
+ tool_choice: { type: "tool", name: "lookup_weather" },
+ output_config: {
+ effort: "high",
+ format: {
+ type: "json_schema",
+ name: "weather_response",
+ schema: {
+ type: "object",
+ properties: { forecast: { type: "string" } },
+ required: ["forecast"],
+ },
+ },
+ },
+ })
+
+ expect(Object.keys(translated).sort()).toEqual([
+ "include",
+ "input",
+ "instructions",
+ "model",
+ "parallel_tool_calls",
+ "reasoning",
+ "store",
+ "stream",
+ "text",
+ "tool_choice",
+ "tools",
+ ])
+ })
})
diff --git a/src/translate/request.ts b/src/translate/request.ts
index 3bf554f..cbd1498 100644
--- a/src/translate/request.ts
+++ b/src/translate/request.ts
@@ -7,6 +7,8 @@ import type {
AnthropicTool,
} from "../anthropic/schema.ts"
+// Keep this aligned to the upstream Codex ResponsesApiRequest field set.
+// Do not add plausible-looking top-level fields without source support or a confirmed live test.
export interface ResponsesRequest {
model: string
instructions?: string
@@ -18,11 +20,12 @@ export interface ResponsesRequest {
| "required"
| { type: "function"; name: string }
parallel_tool_calls?: boolean
+ reasoning?: { effort?: "low" | "medium" | "high"; summary?: unknown }
store: false
stream: true
include?: string[]
+ service_tier?: string
prompt_cache_key?: string
- reasoning?: { effort?: "low" | "medium" | "high" }
text?: {
verbosity?: "low" | "medium" | "high"
format?:
@@ -30,6 +33,7 @@ export interface ResponsesRequest {
| { type: "json_object" }
| { type: "json_schema"; name: string; schema: unknown; strict?: boolean }
}
+ client_metadata?: Record<string, string>
}
export type ResponsesInputItem =