Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Forget a Claude gateway's context windows when its address changes

AdityaUmale028b3bcab552
diff --git a/server/claude-endpoints.test.ts b/server/claude-endpoints.test.ts
index 8e48b3d2f3..7b3936a312 100644
--- a/server/claude-endpoints.test.ts
+++ b/server/claude-endpoints.test.ts
@@ -153,6 +153,15 @@ describe("custom Claude endpoint", () => {
.toMatchObject({ ANTHROPIC_AUTH_TOKEN: "sk-fixture-secret" });
});
+ it("forgets the gateway's reported context windows when the address changes", () => {
+ const { instanceId, instances } = newClaudeEndpoint(cfg(), BASE);
+ (instances[instanceId].config as Record<string, unknown>).endpointContextWindows = { "deepseek-chat": 128_000 };
+ const windows = (update: Parameters<typeof updateClaudeEndpoint>[2]) =>
+ (updateClaudeEndpoint({ instances }, instanceId, update).instances[instanceId].config as Record<string, unknown>).endpointContextWindows;
+ expect(windows({ baseUrl: BASE.baseUrl, displayName: "Renamed" })).toEqual({ "deepseek-chat": 128_000 });
+ expect(windows({ baseUrl: "https://api.example.test/anthropic", token: "sk-moved" })).toBeUndefined();
+ });
+
it("rejects a non-endpoint Claude instance, an unknown id and an endpoint with no token", () => {
const { instances } = newClaudeEndpoint(cfg(), BASE);
expect(() => updateClaudeEndpoint({ instances }, "claude", { model: "deepseek-chat" })).toThrow(/not a custom endpoint/);
diff --git a/server/claude-endpoints.ts b/server/claude-endpoints.ts
index e74d35eeba..a2fbd2c5b4 100644
--- a/server/claude-endpoints.ts
+++ b/server/claude-endpoints.ts
@@ -164,11 +164,14 @@ export function updateClaudeEndpoint(cfg: AppConfig, instanceId: string, body: E
}
const secret = body.token ?? entry.environment?.ANTHROPIC_AUTH_TOKEN ?? entry.environment?.ANTHROPIC_API_KEY;
if (!secret) throw Object.assign(new Error("Enter the endpoint's token."), { status: 400 });
+ const config: Record<string, unknown> = { ...rawConfig(entry), endpointModels: fields.model && (body.model !== undefined || TIERS.some(([field]) => body[field] !== undefined)) ? endpointModels(fields) : saved.models };
+ // Context windows were reported by the old address's gateway.
+ if (address !== endpointBaseUrl(saved.baseUrl)) delete config.endpointContextWindows;
instances[instanceId] = {
...entry,
...(fields.displayName ? { displayName: fields.displayName } : {}),
environment: endpointEnvironment(address, secret, fields),
- config: { ...rawConfig(entry), endpointModels: fields.model && (body.model !== undefined || TIERS.some(([field]) => body[field] !== undefined)) ? endpointModels(fields) : saved.models },
+ config,
};
return { instances };
}