diff --git a/cloud/app/src/routes/zen/v1/chat/completions.ts b/cloud/app/src/routes/zen/v1/chat/completions.ts index 6f206225..090f4aaa 100644 --- a/cloud/app/src/routes/zen/v1/chat/completions.ts +++ b/cloud/app/src/routes/zen/v1/chat/completions.ts @@ -56,6 +56,13 @@ const MODELS = { }, } +const FREE_WORKSPACES = [ + "wrk_01K47W3MEXPJZQ8J14B1NNPS9Z", // adam + "wrk_01K46F9BS6S1RC2W49CH6KSMDN", // dax + "wrk_01K46JDFR0E75SG2Q8K172KF3Y", // frank + "wrk_01K484AYAZ8RA7G32ZB93VZX6M", // jay +] + class AuthError extends Error {} class CreditsError extends Error {} class ModelError extends Error {} @@ -66,6 +73,7 @@ export async function POST(input: APIEvent) { const body = await input.request.json() const MODEL = validateModel() const apiKey = await authenticate() + const isFree = FREE_WORKSPACES.includes(apiKey?.workspaceID ?? "") await checkCredits() // Request to model provider @@ -195,7 +203,7 @@ export async function POST(input: APIEvent) { } async function checkCredits() { - if (!apiKey || !MODEL.auth) return + if (!apiKey || !MODEL.auth || isFree) return const billing = await Database.use((tx) => tx @@ -229,7 +237,7 @@ export async function POST(input: APIEvent) { const cacheReadCost = MODEL.cost.cacheRead * cacheReadTokens const cacheWriteCost = MODEL.cost.cacheWrite * cacheWriteTokens const costInCents = (inputCost + outputCost + reasoningCost + cacheReadCost + cacheWriteCost) * 100 - const cost = centsToMicroCents(costInCents) + const cost = isFree ? 0 : centsToMicroCents(costInCents) await Database.transaction(async (tx) => { await tx.insert(UsageTable).values({