Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Your keys: fal.ai keys are checked at the address fal.ai answers

Adarsh9b3aaacaef45
diff --git a/docs/public-signup.md b/docs/public-signup.md
index 8a46cd4f..82958c99 100644
--- a/docs/public-signup.md
+++ b/docs/public-signup.md
@@ -228,7 +228,7 @@ account with that provider. The studio's own keys are never used for an account'
- **Checked first.** `PUT /api/account/keys/fal` (or `/replicate`) with `{ key }` checks the key
with the provider before it is saved: a free call that runs nothing (fal.ai: the status of a
request that doesn't exist; Replicate: `GET /v1/account`). A refused key answers 422, a provider
- out of reach 502, and nothing is saved. A key that works on a provider account with no balance
+ out of reach 503, and nothing is saved. A key that works on a provider account with no balance
left is saved, with a `note` that says to top it up. `?test=1` only checks. Only a check that
reaches the provider counts: 10 a minute per account, 20 per address (behind a trusted proxy),
120 for all accounts together.
diff --git a/src/server/providers/fal.ts b/src/server/providers/fal.ts
index 51b10c3e..3bbca721 100644
--- a/src/server/providers/fal.ts
+++ b/src/server/providers/fal.ts
@@ -183,13 +183,14 @@ export type KeyCheck = { ok: true; detail: string } | { ok: false; detail: strin
/**
* Check a fal.ai key, and only that key (Settings' "Save & test", an account's Your keys): the status of a request that
* doesn't exist. Free, and nothing runs: 401/403 means a bad key (or, saying so, an empty balance), 404/422 a key that
- * works.
+ * works. The path is the app's (fal-ai/flux), as fal.ai's status paths are: with an endpoint's sub-path
+ * (fal-ai/flux/dev) fal.ai answers 405 to every key.
*/
export async function testFalKey(k: string): Promise<KeyCheck> {
if (!k) return { ok: false, detail: "No key set", reason: "rejected" };
let res: Response;
try {
- res = await fetch(`${falQueue()}/fal-ai/flux/dev/requests/00000000-0000-0000-0000-000000000000/status`, {
+ res = await fetch(`${falQueue()}/fal-ai/flux/requests/00000000-0000-0000-0000-000000000000/status`, {
headers: { Authorization: `Key ${k}` },
signal: AbortSignal.timeout(15_000),
});
diff --git a/src/server/your-keys.ts b/src/server/your-keys.ts
index c55a03c7..600c6fc2 100644
--- a/src/server/your-keys.ts
+++ b/src/server/your-keys.ts
@@ -24,8 +24,9 @@ export async function checkKey(p: CloudProvider, key: string): Promise<{ ok: tru
const hint = settingProblem(CLOUD_KEY[p].setting, key);
return { ok: false, status: 422, error: `${label} didn't accept this key. Copy it again from ${label}'s API keys page.${hint ? ` (${hint}.)` : ""}` };
}
- if (check.reason === "unreachable") return { ok: false, status: 502, error: `Couldn't reach ${label} to check the key, so it wasn't saved. Try again in a moment.` };
- return { ok: false, status: 502, error: `${label} answered ${check.status ?? "oddly"}, so the key couldn't be checked. Try again in a moment.` };
+ // 503, not 502: a proxy in front (Cloudflare) answers an origin's 502 with its own page, and these words would be lost.
+ if (check.reason === "unreachable") return { ok: false, status: 503, error: `Couldn't reach ${label} to check the key, so it wasn't saved. Try again in a moment.` };
+ return { ok: false, status: 503, error: `${label} answered ${check.status ?? "oddly"}, so the key couldn't be checked. Try again in a moment.` };
}
/** The account's runs going on a provider now (queued, running, or a step waiting to be sent there). */
diff --git a/tests/account-keys-routes.test.ts b/tests/account-keys-routes.test.ts
index 97d54ecd..790e21e4 100644
--- a/tests/account-keys-routes.test.ts
+++ b/tests/account-keys-routes.test.ts
@@ -121,12 +121,13 @@ describe("adding a key", () => {
it("says when the provider can't be reached or answers oddly", async () => {
const odd = await put("fal", { key: "outage-key-id-1111:outage-secret-1111" });
- expect(odd.status).toBe(502);
+ // 503, not 502: a proxy in front (Cloudflare) swaps an origin's 502 for its own page, and the words are lost.
+ expect(odd.status).toBe(503);
expect((await odd.json()).error).toBe("fal.ai answered 503, so the key couldn't be checked. Try again in a moment.");
globalThis.__fuobeTestFalUrl = "http://127.0.0.1:9";
try {
const down = await put("fal", { key: GOOD_FAL });
- expect(down.status).toBe(502);
+ expect(down.status).toBe(503);
expect((await down.json()).error).toBe("Couldn't reach fal.ai to check the key, so it wasn't saved. Try again in a moment.");
} finally {
globalThis.__fuobeTestFalUrl = fal.url;
@@ -137,6 +138,8 @@ describe("adding a key", () => {
it("checks only, with ?test=1", async () => {
const r = await put("fal", { key: GOOD_FAL }, "?test=1");
expect(await r.json()).toEqual({ provider: "fal", ok: true, detail: "Key accepted" });
+ // fal.ai's status path without the endpoint's sub-path (with it, fal.ai answers 405 to every key).
+ expect(fal.log.at(-1)?.path).toBe("/fal-ai/flux/requests/00000000-0000-0000-0000-000000000000/status");
expect((await get()).keys.fal).toBeNull();
});
diff --git a/tests/helpers/fake-cloud.ts b/tests/helpers/fake-cloud.ts
index 0f879b17..d1c5389f 100644
--- a/tests/helpers/fake-cloud.ts
+++ b/tests/helpers/fake-cloud.ts
@@ -89,8 +89,12 @@ export function startFakeFal(port = 0): Promise<FakeCloud> {
const path = r.path.split("?")[0];
// A file's upload address: the client sends no key there.
if (r.method === "PUT" && path.startsWith("/upload/")) return json(res, 200, {});
+ // Like fal.ai, a status path keeps only the app's first two parts: one with an endpoint's sub-path
+ // (/fal-ai/flux/dev/requests/…) is 405 whatever the key.
+ if (r.method === "GET" && /^\/[^/]+\/[^/]+\/[^/]+\/requests\//.test(path)) return json(res, 405, {});
if (refused(fake, r, res, key, { status: 403, detail: "User is locked. Reason: Exhausted balance. Top up your balance at fal.ai/dashboard/billing." })) return;
- if (path === `/fal-ai/flux/dev/requests/${ZERO}/status`) return json(res, 404, { detail: "Request not found" });
+ // The key check: the status of a request that doesn't exist.
+ if (path === `/fal-ai/flux/requests/${ZERO}/status`) return json(res, 404, { status: "NOT_FOUND" });
if (r.method === "POST" && path === "/storage/upload/initiate") {
const id = ++n;
return json(res, 200, { upload_url: `${fake.url}/upload/${id}`, file_url: `${fake.url}/files/${id}` });