Skip to content

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

fix(claude): review fixes for the Amazon Bedrock engine (#5261)

milind-soni644a3ff1cad4
diff --git a/server/claude-bedrock.test.ts b/server/claude-bedrock.test.ts
index 700c836b56..cea34d3fd0 100644
--- a/server/claude-bedrock.test.ts
+++ b/server/claude-bedrock.test.ts
@@ -1,7 +1,6 @@
import { join } from "node:path";
import { describe, expect, it } from "vitest";
-import { officialModels } from "./agent-endpoint-models.ts";
import {
claudeBedrockSchema,
claudeBedrockUpdateSchema,
@@ -18,6 +17,7 @@ const BASE = {
displayName: "Bedrock US",
awsProfile: "bedrock-prod",
awsRegion: "us-east-1",
+ model: "global.anthropic.claude-sonnet-5-5",
};
const cfg = () => ({
@@ -47,6 +47,7 @@ describe("Claude on Amazon Bedrock", () => {
CLAUDE_CODE_USE_BEDROCK: "1",
AWS_PROFILE: "bedrock-prod",
AWS_REGION: "us-east-1",
+ ANTHROPIC_MODEL: "global.anthropic.claude-sonnet-5-5",
ANTHROPIC_DEFAULT_OPUS_MODEL: "global.anthropic.claude-opus-5-5",
},
});
@@ -54,8 +55,8 @@ describe("Claude on Amazon Bedrock", () => {
expect(entry.environment).not.toHaveProperty("ANTHROPIC_AUTH_TOKEN");
expect(entry.environment).not.toHaveProperty("requireApiKey");
expect((entry.config as { requireApiKey?: boolean }).requireApiKey).toBeUndefined();
- // No model named: the default catalog is every official model under Bedrock's cross-region prefix.
- expect((entry.config as { endpointModels: string[] }).endpointModels).toEqual(officialModels(false).map((id) => `global.anthropic.${id}`));
+ // The catalog is the named model and each tier set, never guessed Bedrock ids.
+ expect((entry.config as { endpointModels: string[] }).endpointModels).toEqual(["global.anthropic.claude-sonnet-5-5", "global.anthropic.claude-opus-5-5"]);
// The caller's config is left as it was: the fleet is copied, not edited.
expect(Object.keys((source as { instances: object }).instances)).toEqual(["claude", "other"]);
});
@@ -72,17 +73,18 @@ describe("Claude on Amazon Bedrock", () => {
});
it("uses an explicit model as the only catalog entry when none of the tiers are set", () => {
- const { instanceId, instances } = newClaudeBedrock(cfg(), { ...BASE, model: "global.anthropic.claude-sonnet-5-5" });
+ const { instanceId, instances } = newClaudeBedrock(cfg(), BASE);
expect((instances[instanceId].config as { endpointModels: string[] }).endpointModels).toEqual(["global.anthropic.claude-sonnet-5-5"]);
expect(instances[instanceId].environment?.ANTHROPIC_MODEL).toBe("global.anthropic.claude-sonnet-5-5");
});
it("reports only the profile, region and models to a client; never an AWS or Anthropic secret", () => {
- const { instanceId, instances } = newClaudeBedrock(cfg(), { ...BASE, model: "global.anthropic.claude-sonnet-5-5" });
+ const { instanceId, instances } = newClaudeBedrock(cfg(), BASE);
const info = claudeBedrockInfo(instances[instanceId]);
expect(info).toEqual({
awsProfile: "bedrock-prod",
awsRegion: "us-east-1",
+ model: "global.anthropic.claude-sonnet-5-5",
models: ["global.anthropic.claude-sonnet-5-5"],
opusModel: "", sonnetModel: "", haikuModel: "", smallFastModel: "",
});
@@ -134,6 +136,7 @@ describe("Claude on Amazon Bedrock", () => {
{ ...BASE, awsRegion: "US-EAST-1" },
{ ...BASE, model: "has space" },
{ ...BASE, model: "" },
+ { displayName: BASE.displayName, awsProfile: BASE.awsProfile, awsRegion: BASE.awsRegion },
{ ...BASE, model: "default" },
{ ...BASE, displayName: "Bad\nname" },
{ ...BASE, displayName: "" },
diff --git a/server/claude-bedrock.ts b/server/claude-bedrock.ts
index dc56da628f..c91a884576 100644
--- a/server/claude-bedrock.ts
+++ b/server/claude-bedrock.ts
@@ -7,7 +7,6 @@ import type { ClaudeBedrockInfo } from "../shared/claude-endpoint.ts";
import { assertSeparateClaudeAccount } from "./claude-accounts.ts";
import { DATA_DIR, persistableInstanceConfigs, type AppConfig } from "./config.ts";
import type { InstanceConfig, InstanceConfigMap } from "./contracts.ts";
-import { officialModels } from "./agent-endpoint-models.ts";
import { CLAUDE_MODEL_ID } from "./drivers/claude-model-extras.ts";
const displayName = z.string().trim().min(1).max(80).refine((value) => !/\p{Cc}/u.test(value), "Name cannot contain control characters");
@@ -21,7 +20,7 @@ export const claudeBedrockSchema = z.object({
displayName,
awsProfile,
awsRegion,
- model: model.optional(),
+ model,
opusModel: optionalModel.optional(),
sonnetModel: optionalModel.optional(),
haikuModel: optionalModel.optional(),
@@ -68,6 +67,7 @@ export function claudeBedrockInfo(entry: InstanceConfig): ClaudeBedrockInfo {
return {
awsProfile: environment.AWS_PROFILE ?? "",
awsRegion: environment.AWS_REGION ?? "",
+ model: environment.ANTHROPIC_MODEL ?? "",
models: Array.isArray(config.endpointModels) ? [...config.endpointModels] : [],
opusModel: environment.ANTHROPIC_DEFAULT_OPUS_MODEL ?? "",
sonnetModel: environment.ANTHROPIC_DEFAULT_SONNET_MODEL ?? "",
@@ -104,11 +104,6 @@ function bedrockModels(fields: ResolvedBedrockFields): string[] {
return [...new Set([(fields.model ?? "").trim(), ...tiers].filter(Boolean))];
}
-/** Bedrock's own id for each official model, Claude Code's cross-region inference profile prefix. */
-function defaultBedrockModels(): string[] {
- return officialModels(false).map((id) => `global.anthropic.${id}`);
-}
-
function inheritedCli(instances: InstanceConfigMap): string | undefined {
for (const entry of Object.values(instances)) {
if (entry.driver !== "claudeAgent" || isClaudeBedrock(entry)) continue;
@@ -130,7 +125,7 @@ export function newClaudeBedrock(cfg: AppConfig, body: z.infer<typeof claudeBedr
...(cli ? { cli } : {}),
configDir: join(DATA_DIR, "providers", instanceId),
bedrock: true,
- endpointModels: body.model ? bedrockModels(body) : defaultBedrockModels(),
+ endpointModels: bedrockModels(body),
},
environment: bedrockEnvironment(body),
};
diff --git a/server/drivers/claude-billing.test.ts b/server/drivers/claude-billing.test.ts
new file mode 100644
index 0000000000..1f1eef8dac
--- /dev/null
+++ b/server/drivers/claude-billing.test.ts
@@ -0,0 +1,18 @@
+import { describe, expect, it } from "vitest";
+
+import { claudeBilling } from "./claude-billing.ts";
+
+describe("claudeBilling", () => {
+ it("counts a Claude Code login as the plan", () => {
+ expect(claudeBilling({}, { email: "[email protected]" })).toEqual({ billing: "subscription" });
+ });
+
+ it("meters an API key in the environment", () => {
+ expect(claudeBilling({ ANTHROPIC_API_KEY: "sk-ant-fixture" }, undefined)).toEqual({ account: { method: "api-key" }, billing: "metered" });
+ });
+
+ it("meters Amazon Bedrock, which bills the AWS account per token, even with a login on the computer", () => {
+ expect(claudeBilling({ CLAUDE_CODE_USE_BEDROCK: "1", AWS_PROFILE: "bedrock-prod" }, { email: "[email protected]" })).toEqual({ billing: "metered" });
+ expect(claudeBilling({ CLAUDE_CODE_USE_BEDROCK: "0" }, undefined)).toEqual({ billing: "subscription" });
+ });
+});
diff --git a/server/drivers/claude-billing.ts b/server/drivers/claude-billing.ts
index d974b2025c..5d7be8c1cd 100644
--- a/server/drivers/claude-billing.ts
+++ b/server/drivers/claude-billing.ts
@@ -1,8 +1,9 @@
import type { ProviderSnapshot } from "../contracts.ts";
/** What a Claude instance's turns bill: `claude -p` runs on an ANTHROPIC_API_KEY in its environment ahead of any login,
- * billed per token (2.1.303), as it does on the CLI's own API-key sign-in. */
+ * billed per token (2.1.303), as it does on the CLI's own API-key sign-in. Amazon Bedrock bills the AWS account per token. */
export function claudeBilling(env: NodeJS.ProcessEnv, account: ProviderSnapshot["account"]): Pick<ProviderSnapshot, "account" | "billing"> {
+ if (env.CLAUDE_CODE_USE_BEDROCK === "1") return { billing: "metered" };
return env.ANTHROPIC_API_KEY || account?.method === "api-key"
? { account: { ...account, method: "api-key" }, billing: "metered" }
: { billing: "subscription" };
diff --git a/shared/claude-endpoint.ts b/shared/claude-endpoint.ts
index b4e9f340f8..98b32e2d55 100644
--- a/shared/claude-endpoint.ts
+++ b/shared/claude-endpoint.ts
@@ -13,6 +13,7 @@ export interface ClaudeEndpointInfo {
export interface ClaudeBedrockInfo {
awsProfile: string;
awsRegion: string;
+ model: string;
models: string[];
opusModel: string;
sonnetModel: string;
diff --git a/src/components/ClaudeBedrock.dom.test.ts b/src/components/ClaudeBedrock.dom.test.ts
index 22e2b75548..6280a95e15 100644
--- a/src/components/ClaudeBedrock.dom.test.ts
+++ b/src/components/ClaudeBedrock.dom.test.ts
@@ -14,7 +14,7 @@ const bedrockInstance = () => ({
snapshot: { state: "available" },
models: { default: "", options: [] },
claudeBedrock: {
- awsProfile: "default", awsRegion: "us-east-1", models: ["global.anthropic.claude-opus-5-5"],
+ awsProfile: "default", awsRegion: "us-east-1", model: "global.anthropic.claude-opus-5-5", models: ["global.anthropic.claude-opus-5-5"],
opusModel: "global.anthropic.claude-opus-5-5", sonnetModel: "", haikuModel: "", smallFastModel: "",
},
}) as unknown as store.InstanceInfo;
@@ -54,7 +54,17 @@ afterEach(() => {
});
describe("adding a Claude on Amazon Bedrock engine", () => {
- it("posts the profile, region and only the filled model fields, trimmed", async () => {
+ it("waits for a model before it can be saved", () => {
+ mount([]);
+ flushSync(() => host.querySelector<HTMLButtonElement>("button")!.click());
+ setValue(host.querySelector<HTMLInputElement>('input[aria-label="AWS region"]')!, "us-west-2");
+ const submit = host.querySelector<HTMLButtonElement>('button[type="submit"]')!;
+ expect(submit.disabled).toBe(true);
+ setValue(host.querySelector<HTMLInputElement>('input[aria-label="Model"]')!, "global.anthropic.claude-sonnet-5-5");
+ expect(submit.disabled).toBe(false);
+ });
+
+ it("posts the profile, region and model fields, trimmed", async () => {
mount([]);
flushSync(() => host.querySelector<HTMLButtonElement>("button")!.click());
const name = host.querySelector<HTMLInputElement>('input[aria-label="Name"]')!;
@@ -63,6 +73,7 @@ describe("adding a Claude on Amazon Bedrock engine", () => {
setValue(name, " Team Bedrock ");
setValue(profile, " my-profile ");
setValue(region, " us-west-2 ");
+ setValue(host.querySelector<HTMLInputElement>('input[aria-label="Model"]')!, " global.anthropic.claude-sonnet-5-5 ");
const form = host.querySelector<HTMLFormElement>("form")!;
await flushSync(() => { form.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true })); });
await Promise.resolve();
@@ -73,7 +84,7 @@ describe("adding a Claude on Amazon Bedrock engine", () => {
expect(init.method).toBe("POST");
const body = JSON.parse(String(init.body));
expect(body).toEqual({
- displayName: "Team Bedrock", awsProfile: "my-profile", awsRegion: "us-west-2",
+ displayName: "Team Bedrock", awsProfile: "my-profile", awsRegion: "us-west-2", model: "global.anthropic.claude-sonnet-5-5",
opusModel: "", sonnetModel: "", haikuModel: "", smallFastModel: "",
});
});
@@ -96,5 +107,6 @@ describe("adding a Claude on Amazon Bedrock engine", () => {
const body = JSON.parse(String(init.body));
expect(body.opusModel).toBe("");
expect(body.awsProfile).toBe("default");
+ expect(body.model).toBe("global.anthropic.claude-opus-5-5");
});
});
diff --git a/src/components/ClaudeBedrock.test.ts b/src/components/ClaudeBedrock.test.ts
index 17226019e9..bc08874cd5 100644
--- a/src/components/ClaudeBedrock.test.ts
+++ b/src/components/ClaudeBedrock.test.ts
@@ -15,7 +15,7 @@ const bedrock = (extra: Record<string, unknown> = {}) => ({
claudeBedrock: {
awsProfile: "theiconic-claude-primary",
awsRegion: "us-east-1",
- models: ["global.anthropic.claude-sonnet-5-5"],
+ model: "global.anthropic.claude-sonnet-5-5", models: ["global.anthropic.claude-sonnet-5-5"],
opusModel: "au.anthropic.claude-opus-5-5", sonnetModel: "", haikuModel: "", smallFastModel: "",
},
...extra,
diff --git a/src/components/ClaudeBedrock.tsx b/src/components/ClaudeBedrock.tsx
index 07f9407c36..e43ac0adb1 100644
--- a/src/components/ClaudeBedrock.tsx
+++ b/src/components/ClaudeBedrock.tsx
@@ -37,7 +37,7 @@ const draftOf = (instance: InstanceInfo): Draft => {
name: instance.displayName,
awsProfile: bedrock?.awsProfile || "default",
awsRegion: bedrock?.awsRegion ?? "",
- model: "",
+ model: bedrock?.model ?? "",
opusModel: bedrock?.opusModel ?? "",
sonnetModel: bedrock?.sonnetModel ?? "",
haikuModel: bedrock?.haikuModel ?? "",
@@ -63,7 +63,7 @@ function BedrockForm({ instance, onDone }: { instance?: InstanceInfo; onDone: ()
spellCheck: false,
disabled: saving,
});
- const ready = Boolean(draft.name.trim() && draft.awsProfile.trim() && draft.awsRegion.trim());
+ const ready = Boolean(draft.name.trim() && draft.awsProfile.trim() && draft.awsRegion.trim() && draft.model.trim());
const save = async () => {
if (saving || !ready) return;
@@ -73,7 +73,7 @@ function BedrockForm({ instance, onDone }: { instance?: InstanceInfo; onDone: ()
displayName: draft.name.trim(),
awsProfile: draft.awsProfile.trim(),
awsRegion: draft.awsRegion.trim(),
- ...(draft.model.trim() ? { model: draft.model.trim() } : {}),
+ model: draft.model.trim(),
...Object.fromEntries(TIERS.map((tier) => [tier, draft[tier].trim()])),
};
try {
diff --git a/src/components/EnginesSettings.test.ts b/src/components/EnginesSettings.test.ts
index 711df2b62f..3a452457f0 100644
--- a/src/components/EnginesSettings.test.ts
+++ b/src/components/EnginesSettings.test.ts
@@ -499,7 +499,7 @@ describe("Settings → Engines → custom Claude endpoints", () => {
{
instanceId: "claude-bedrock-1", driverKind: "claudeAgent", displayName: "Claude on Bedrock", access: "custom",
snapshot: { state: "available" }, models: { default: "", options: [] },
- claudeBedrock: { awsProfile: "default", awsRegion: "us-east-1", models: [], opusModel: "", sonnetModel: "", haikuModel: "", smallFastModel: "" },
+ claudeBedrock: { awsProfile: "default", awsRegion: "us-east-1", model: "global.anthropic.claude-sonnet-5-5", models: ["global.anthropic.claude-sonnet-5-5"], opusModel: "", sonnetModel: "", haikuModel: "", smallFastModel: "" },
},
];
fixture.bots = [];
diff --git a/src/locales/en.json b/src/locales/en.json
index e5b3f8b61b..b874ad33e9 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -4567,7 +4567,7 @@
"claudeEndpoints.removeBody": "This removes the endpoint from app settings. The bots that used it need another model.",
"claudeEndpoints.failed": "Couldn't save the endpoint. Check the fields and try again.",
"claudeBedrock.title": "Amazon Bedrock",
- "claudeBedrock.hint": "Run this account's bots on Claude through Amazon Bedrock, signed in with an AWS profile from this computer. It is its own engine, so the Claude Code on this computer and its sign-in stay as they are.",
+ "claudeBedrock.hint": "Run bots on Claude through Amazon Bedrock, signed in with an AWS profile from this computer. It is its own engine, so the Claude Code on this computer and its sign-in stay as they are.",
"claudeBedrock.awsHint": "Uses the AWS profile from this computer's ~/.aws config. Run `aws sso login --profile …` first if it uses SSO.",
"claudeBedrock.empty": "No Amazon Bedrock engines yet.",
"claudeBedrock.add": "Add Amazon Bedrock",
@@ -4576,7 +4576,7 @@
"claudeBedrock.profile": "AWS profile",
"claudeBedrock.region": "AWS region",
"claudeBedrock.model": "Model",
- "claudeBedrock.modelHint": "Optional. Leave it empty and OpenMausBot uses Bedrock's standard Claude models. Each bot then picks its own model.",
+ "claudeBedrock.modelHint": "The Bedrock model id or inference profile {app} runs, as your AWS account lists it. Each bot then picks this model or a tier model below.",
"claudeBedrock.tiers": "Model per tier",
"claudeBedrock.opus": "Opus model",
"claudeBedrock.sonnet": "Sonnet model",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 6ccccd5d3e..5dbd28c38a 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -4306,6 +4306,26 @@
"claudeEndpoints.remove": "Remover {name}",
"claudeEndpoints.removeBody": "Isso remove o endpoint das configurações do app. Os bots que o usavam vão precisar de outro modelo.",
"claudeEndpoints.failed": "Não foi possível salvar o endpoint. Verifique os campos e tente novamente.",
+ "claudeBedrock.title": "Amazon Bedrock",
+ "claudeBedrock.hint": "Rode os bots no Claude pelo Amazon Bedrock, com login por um perfil da AWS deste computador. É uma IA à parte, então o Claude Code deste computador e o login dele continuam como estão.",
+ "claudeBedrock.awsHint": "Usa o perfil da AWS da configuração ~/.aws deste computador. Se ele usar SSO, rode `aws sso login --profile …` antes.",
+ "claudeBedrock.empty": "Nenhuma IA do Amazon Bedrock ainda.",
+ "claudeBedrock.add": "Adicionar Amazon Bedrock",
+ "claudeBedrock.edit": "Editar",
+ "claudeBedrock.name": "Nome",
+ "claudeBedrock.profile": "Perfil da AWS",
+ "claudeBedrock.region": "Região da AWS",
+ "claudeBedrock.model": "Modelo",
+ "claudeBedrock.modelHint": "O ID do modelo ou o perfil de inferência do Bedrock que o {app} usa, como aparece na sua conta da AWS. Depois, cada bot escolhe este modelo ou um modelo por nível abaixo.",
+ "claudeBedrock.tiers": "Modelo por nível",
+ "claudeBedrock.opus": "Modelo para Opus",
+ "claudeBedrock.sonnet": "Modelo para Sonnet",
+ "claudeBedrock.haiku": "Modelo para Haiku",
+ "claudeBedrock.smallFast": "Modelo rápido e pequeno",
+ "claudeBedrock.rowSubtitle": "Bedrock · {profile} · {region}",
+ "claudeBedrock.remove": "Remover {name}",
+ "claudeBedrock.removeBody": "Isso remove a IA do Bedrock das configurações do app. Os bots que a usavam vão precisar de outro modelo.",
+ "claudeBedrock.failed": "Não foi possível salvar a IA do Bedrock. Verifique os campos e tente novamente.",
"engines.none": "Nenhum app de provedor de modelos detectado ainda.",
"engines.footer": "Definir CLI permite escolher um executável específico para o provedor de modelos: uma versão, um script intermediário ou um caminho absoluto. As alterações só são salvas quando o provedor escolhido está sem atividade. Os outros provedores continuam funcionando.",
"engines.freeSpace.title": "Arquivos restantes",