diff --git a/index.mjs b/index.mjs index 3fd75af..20b215a 100644 --- a/index.mjs +++ b/index.mjs @@ -41,9 +41,9 @@ async function exchange(code, verifier) { const result = await fetch("https://console.anthropic.com/v1/oauth/token", { method: "POST", headers: { - "Content-Type": "application/json", + "Content-Type": "application/x-www-form-urlencoded", }, - body: JSON.stringify({ + body: new URLSearchParams({ code: splits[0], state: splits[1], grant_type: "authorization_code", @@ -74,6 +74,7 @@ export async function AnthropicAuthPlugin({ client }) { provider: "anthropic", async loader(getAuth, provider) { const auth = await getAuth(); + if (!auth) return {}; if (auth.type === "oauth") { // zero out cost for max plan for (const model of Object.values(provider.models)) { @@ -101,9 +102,9 @@ export async function AnthropicAuthPlugin({ client }) { { method: "POST", headers: { - "Content-Type": "application/json", + "Content-Type": "application/x-www-form-urlencoded", }, - body: JSON.stringify({ + body: new URLSearchParams({ grant_type: "refresh_token", refresh_token: auth.refresh, client_id: CLIENT_ID,