diff options
| author | Frank <[email protected]> | 2025-09-03 15:35:46 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-09-03 15:35:46 -0400 |
| commit | 93f507d33011ac04f2ab2fd373b13721dddf4e1f (patch) | |
| tree | be0b1a314a64076131c79ad70eb1c5dbc0ba55ab /cloud/app/src/routes | |
| parent | 7119ace9405a53158fbf3382467179cf4174bf4f (diff) | |
| download | opencode-93f507d33011ac04f2ab2fd373b13721dddf4e1f.tar.gz opencode-93f507d33011ac04f2ab2fd373b13721dddf4e1f.zip | |
wip console
Diffstat (limited to 'cloud/app/src/routes')
| -rw-r--r-- | cloud/app/src/routes/zen/v1/chat/completions.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/cloud/app/src/routes/zen/v1/chat/completions.ts b/cloud/app/src/routes/zen/v1/chat/completions.ts index 6f206225c..090f4aaa3 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({ |
