Flux-1-schnell cost and limits

What is the name of the modal you’re running?

[modal or model???] @cf/black-forest-labs/flux-1-schnell

What is the issue or error you’re encountering

So, I see this pricing info $0.0000528 per 512x512 tile $0.0001056 per step. I’m not fully understand how it applied to resulting image. Say, I’ve set it to 6 steps. The returned image is always 1024x1024, does it means it is 4 tiles? how are steps applied, per tile or per image? I’ve run several API calls to this model (without AI gateway and with) but I can’t see returned cost anywhere. Also, in the cloudflare discord I see report about limit to the number of calls to this model per month, but I don’t see info about limits in docs.

Hi,

Breakdown Cost $ Cost Neurons
512x512 Tile 0.0000528 4.8
Step $0.0001056 9.6

The steps are applied to each tile. So for a 1024x1024 image with 6 steps you have the following

In neurons:
= 4 x 4.8 + [steps]49.6
= 19.2 + steps × 38.4
= 19.2 + 6 × 38.4
= 249.6 Neurons

You can see the usage stats here:

https://dash.cloudflare.com/?to=/:account/ai/workers-ai

For text to image you are limited to 720 requests per minute

Thanks for the pricing formula!
As to the usage stats - yes I see the stats for overall calls, but I was looking about usage of tokens/neurons in individual call. I don’t see it in api response nor in ai gateway log.

About limits - yes, I checked this page, but I concerned about a cloudflare user reported this error in his usage of this model:
“Monthly usage limit for image reached for your plan. Please upgrade.” (and he is on the Workers Paid plan)

skip the question about limits - this user updated report that the error wasn’t from the AI-model usage.
So, my question is about where to get info of individual usage of tokens/neurons in API call

So, I’ve had a play with this…

You have this api

/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs
Cloudflare API | AI Gateway › Logs › List Gateway Logs

And then you have

/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs/{id}/request
/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs/{id}/response

You can also call

/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs/{id}

We can see on these request that there are response fields for tokens and cost but neither are populated. Probably still in development

I have a workaround using a worker to query the API and return the data you want.

Code
export default {
  async fetch(request, env, ctx) {
    const url = new URL(request.url);
    const accountId = "xxxxxxxxxxxxxxxxxxxxxxxx";
    const gatewayId = "ai-gateway-flowmata";

    const headers = {
      'X-Auth-Email': 'cloudflare email',
      'X-Auth-Key': 'global api key',
      'Content-Type': 'application/json'
    };

    const queryParams = Object.fromEntries(url.searchParams.entries());
    delete queryParams.account_id;
    delete queryParams.gateway_id;

    const listUrl = new URL(`https://api.cloudflare.com/client/v4/accounts/${accountId}/ai-gateway/gateways/${gatewayId}/logs`);
    for (const [key, value] of Object.entries(queryParams)) {
      listUrl.searchParams.append(key, value);
    }



    const listResp = await fetch(listUrl.toString(), { headers });
    if (!listResp.ok) {
      return new Response(await listResp.text(), { status: listResp.status });
    }

    const { result: logs } = await listResp.json();

    const results = await Promise.all(logs.map(async ({ id }) => {
      const detailUrl = `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai-gateway/gateways/${gatewayId}/logs/${id}`;
      const detailResp = await fetch(detailUrl, { headers });
      if (!detailResp.ok) return null;

      const { result } = await detailResp.json();
      if (!result?.model) return null;

      let steps = null;
      let price = null;
      let parsed = null;

      if (result.model === "@cf/black-forest-labs/flux-1-schnell") {
        try {
          parsed = JSON.parse(result.request_head || '{}');
          steps = parsed.steps;
          if (typeof steps === "number") {
            //price = 19.2 + steps * 38.4;
            price = Math.round((19.2 + steps * 38.4) * 100) / 100;
          }
        } catch (_) {}
      }

      return {
        id: result.id,
        created_at: result.created_at,
        model: result.model,
        prompt: parsed.prompt,
        steps,
        price
      };
    }));

    const filtered = results.filter(Boolean);
    return new Response(JSON.stringify(filtered, null, 2), {
      headers: { 'Content-Type': 'application/json' }
    });
  }
}

Yes, I see the fields, and I remember when I tested with some other models I got returned costs. I wonder where should I report this.
As to workaround with the price formula - thanks, I thought about this as plan B.
Thank you, HenryB!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.