Skip to content

Commit 43894b0

Browse files
committed
Fix max_tokens OpenAI compatibility
1 parent 4050bf6 commit 43894b0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ const providers: CreateAnthropicProxyOptions["providers"] = {
1818
openai: createOpenAI({
1919
apiKey: process.env.OPENAI_API_KEY,
2020
baseURL: process.env.OPENAI_API_URL,
21+
fetch: (async (url, init) => {
22+
if (init?.body && typeof init.body === "string") {
23+
const body = JSON.parse(init.body);
24+
const maxTokens = body.max_tokens;
25+
delete body["max_tokens"];
26+
body.max_completion_tokens = maxTokens;
27+
init.body = JSON.stringify(body);
28+
}
29+
return globalThis.fetch(url, init);
30+
}) as typeof fetch,
2131
}),
2232
azure: createAzure({
2333
apiKey: process.env.AZURE_API_KEY,

0 commit comments

Comments
 (0)