fal-ai / fal-js

The JavaScript client and utilities to fal-serverless with built-in TypeScript definitions
https://fal.ai
MIT License
91 stars 19 forks source link

Doesn't work on server #97

Closed ollyde closed 3 weeks ago

ollyde commented 1 month ago

I want to use this on a standard nodejs server, as it should be because of api keys.

    fal.config({
      credentials: env.falApiKey,
    });
    const result = await fal.subscribe('fal-ai/flux-realism', {
      input: {
        prompt: prompt,
      },
      logs: true,
      onQueueUpdate: (update) => {
        if (update.status === 'IN_PROGRESS') {
          update.logs.map((log) => log.message).forEach(console.log);
        }
      },
    });
    console.log(result.data);
    console.log(result.requestId);

I get the error

Your environment does not support fetch. Please provide your own fetch implementation.

I'm using node-fetch.

drochetti commented 3 weeks ago

Hey @ollyde if you runtime doesn't provide a global fetch implementation you need to pass it to the config() call.

So you can:

import fetch from 'node-fetch';

fal.config({
  credentials: env.falApiKey,
  fetch,
});
ollyde commented 3 weeks ago

@drochetti it was simple. The docker container on the node server was using node 16 not 22. The error should just say that instead of being cryptic.