Val Town + Fal Partnership

Steve Krouse on

Fal is an API for generating AI images lightning fast.

Today we’re announcing a partnership with Fal to bring their API to Val Town users. You can now use Fal in your vals right away – no Fal API key necessary.

Quickstart vals

The quickest way to get started is to fork one of these starter apps:

Click “Fork” on either of these apps, and you’ll instantly get that app deployed in your Val Town account. No further setup necessary. You can then ask Townie to customize it to your needs. Want a DnD character generator? No problem! Want a tool to help you design your next tattoo? Done!

Instructions for Townie

Another quick way to get started is to copy & paste instructions into Townie. The following instructions will give Townie everything it needs to use Flux Schnell, a state-of-the-art 12b parameter image model by Black Forest Labs. Fal supports the whole Flux suite, and you can use any of them by changing the FAL_ENDPOINT variable.

The following are instructions on how to use Fal,
an image generation API, in your Val Town app.
Import the necessary modules:
```ts
import { falProxyRequest } from "https://esm.town/v/stevekrouse/falProxyRequest";
import { createFalClient } from "https://esm.sh/@fal-ai/client";
```
Set up the Fal client on the client side:
```ts
const FAL_ENDPOINT = "fal-ai/flux/schnell";
const fal = createFalClient({
proxyUrl: "/api/fal/proxy",
});
```
Use the Fal client to handle image generation requests on the client:
```ts
const result = await fal.subscribe("fal-ai/flux/schnell", {
input: {
prompt,
image_size: "landscape_4_3",
num_inference_steps: 4, // must be 12 or less
num_images: 1,
enable_safety_checker: true,
sync_mode: true,
},
});
const image_url = result.data.images[0].url;
```
Set up the Fal proxy request on the server side:
```ts
export default async function server(req: Request): Promise<Response> {
const url = new URL(req.url);
if (url.pathname === "/") {
/* Return HTML */
}
if (url.pathname === "/api/fal/proxy") {
return falProxyRequest(req);
}
}
```

Limitations

This partnership is intended for prototyping and small-scale projects, and is rate-limited as follows:

  • Val Town Free Users: 10 requests per hour
  • Val Town Pro Users: 50 requests per hour

When your project needs scale, you can sign up for a Fal API key here.

How it works

Normally to use the Fal API, you’d need to sign up for an API key on their website, but with this partnership, you can start prototyping with Fal in your vals without any setup. This is possible because we’re proxying requests to the Fal API through this HTTP val, which uses your Val Town API token to authenticate and rate-limit you. In this way you’re using your Val Town API key in place of a Fal API key.

This is how our OpenAI integration works as well, through this proxy. I recently built a similar proxy for SocialData, a Twitter data API provider, which Val Town Pro users can use to run this twitterAlert notifying.

We think of these ‘userspace proxies’ as the beginnings of what we hope will become ‘Val Town Marketplace’. If you want to bring your API to Val Town users, email me at steve@val.town.

Edit this page