diff --git a/apps/demo-nextjs-app-router/app/page.tsx b/apps/demo-nextjs-app-router/app/page.tsx
index e3a6062..a24c7c5 100644
--- a/apps/demo-nextjs-app-router/app/page.tsx
+++ b/apps/demo-nextjs-app-router/app/page.tsx
@@ -82,7 +82,7 @@ export default function Home() {
const start = Date.now();
try {
const result: Result = await fal.subscribe(
- '54285744-illusion-diffusion',
+ '54285744/illusion-diffusion',
{
input: {
prompt,
diff --git a/apps/demo-nextjs-page-router/pages/index.tsx b/apps/demo-nextjs-page-router/pages/index.tsx
index 0f121ab..6bde8b6 100644
--- a/apps/demo-nextjs-page-router/pages/index.tsx
+++ b/apps/demo-nextjs-page-router/pages/index.tsx
@@ -74,13 +74,13 @@ export function Index() {
setLoading(true);
const start = Date.now();
try {
- const result: Result = await fal.subscribe('110602490-lora', {
+ const result: Result = await fal.subscribe('110602490/lora', {
input: {
prompt,
model_name: 'stabilityai/stable-diffusion-xl-base-1.0',
image_size: 'square_hd',
},
- pollInterval: 5000, // Default is 1000 (every 1s)
+ pollInterval: 3000, // Default is 1000 (every 1s)
logs: true,
onQueueUpdate(update) {
setElapsedTime(Date.now() - start);
diff --git a/libs/client/src/function.spec.ts b/libs/client/src/function.spec.ts
index 4b695fb..6c47667 100644
--- a/libs/client/src/function.spec.ts
+++ b/libs/client/src/function.spec.ts
@@ -1,5 +1,4 @@
import uuid from 'uuid-random';
-import { getConfig } from './config';
import { buildUrl } from './function';
describe('The function test suite', () => {
@@ -9,10 +8,10 @@ describe('The function test suite', () => {
expect(url).toMatch(`trigger/12345/${id}`);
});
- it('should build the URL with a function user-id/app-alias', () => {
+ it('should build the URL with a function user-id-app-alias', () => {
const alias = '12345-some-alias';
const url = buildUrl(alias);
- expect(url).toMatch(`${alias}.gateway.alpha.fal.ai`);
+ expect(url).toMatch(`fal.run/12345/some-alias`);
});
it('should build the URL with a function username/app-alias', () => {
diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts
index 89dd934..92f297a 100644
--- a/libs/client/src/function.ts
+++ b/libs/client/src/function.ts
@@ -1,8 +1,7 @@
-import { getConfig } from './config';
import { dispatchRequest } from './request';
import { storageImpl } from './storage';
import { EnqueueResult, QueueStatus } from './types';
-import { isLegacyAppId, isUUIDv4, isValidUrl } from './utils';
+import { ensureAppIdFormat, isUUIDv4, isValidUrl } from './utils';
/**
* The function input and other configuration when running
@@ -36,6 +35,15 @@ type RunOptions = {
readonly autoUpload?: boolean;
};
+type ExtraOptions = {
+ /**
+ * If `true`, the function will use the queue to run the function
+ * asynchronously and return the result in a separate call. This
+ * influences how the URL is built.
+ */
+ readonly subdomain?: string;
+};
+
/**
* Builds the final url to run the function based on its `id` or alias and
* a the options from `RunOptions`.
@@ -47,7 +55,7 @@ type RunOptions = {
*/
export function buildUrl(
id: string,
- options: RunOptions = {}
+ options: RunOptions & ExtraOptions = {}
): string {
const method = (options.method ?? 'post').toLowerCase();
const path = (options.path ?? '').replace(/^\//, '').replace(/\/{2,}/, '/');
@@ -65,26 +73,20 @@ export function buildUrl(
}
// TODO remove this after some time, fal.run should be preferred
- const host = 'gateway.alpha.fal.ai';
if (parts.length === 2 && isUUIDv4(parts[1])) {
+ const host = 'gateway.shark.fal.ai';
return `https://${host}/trigger/${id}/${path}${queryParams}`;
}
- if (isLegacyAppId(id)) {
- return `https://${id}.${host}/${path}${queryParams}`;
- }
- return `https://fal.run/${id}/${path}${queryParams}`;
+ const appId = ensureAppIdFormat(id);
+ const subdomain = options.subdomain ? `${options.subdomain}.` : '';
+ const url = `https://${subdomain}matteo.shark.fal.run/${appId}/${path}`;
+ return `${url.replace(/\/$/, '')}${queryParams}`;
}
-/**
- * Runs a fal serverless function identified by its `id`.
- *
- * @param id the registered function revision id or alias.
- * @returns the remote function output
- */
-export async function run(
+export async function send(
id: string,
- options: RunOptions = {}
+ options: RunOptions & ExtraOptions = {}
): Promise