Skip to content

[Feature]: size and quality keyed cost tracking for fal_ai gpt-image-2 #37738

Description

@mateo-berri

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

The Feature

Price fal_ai image generation by the size and quality actually requested instead of one flat output_cost_per_image. fal bills openai/gpt-image-2 per image at rates that vary with both dimensions (pricing table on https://fal.ai/models/openai/gpt-image-2), from roughly $0.04 to $0.36 per image. PR #37729 adds the model with a single flat rate of $0.145 and documents the variance only in metadata.notes inside model_prices_and_context_window.json, so every non-default request records spend that differs from the fal invoice, silently and in either direction. A quality hd 1024x1024 image bills $0.211 on fal but logs $0.145, a 31% under-count that compounds across requests and makes budget and rate limit enforcement drift. The unprefixed alias fal_ai/gpt-image-2 (accepted since the config auto-prefixes it) has no cost map entry at all and logs $0. Requested: keyed per-image pricing (size x quality) for fal image models, applied from the request parameters at spend-logging time, plus a cost map entry for the unprefixed alias

User Flow

Before this feature (today): a proxy admin routing image generation to fal gets $0.145 logged for every image no matter what size or quality was requested, so LiteLLM budgets stop matching the fal invoice

  1. POST http://localhost:4000/v1/images/generations with {"model": "gpt-image-2-fal", "prompt": "...", "quality": "hd", "size": "1024x1024"} and a virtual key, response is 200 with a fal.media PNG url
  2. Open the Logs page on http://localhost:4000/ui and find the request, the row shows $0.145 spend
  3. Compare with the fal dashboard usage page for the same call, fal billed $0.211, and the gap repeats on every non-default request
  4. POST the same body with "model": "gpt-image-2-fal-shortname" (an alias for fal_ai/gpt-image-2), response is 200 with a real image but the Logs row shows $0.00

After this feature (ideal user flow): the same admin sees LiteLLM spend match the fal invoice for every size and quality combination

  1. POST http://localhost:4000/v1/images/generations with the same quality: "hd", size: "1024x1024" body, response is unchanged
  2. The Logs page row for that request shows $0.211
  3. The fal dashboard usage page and LiteLLM spend agree within rounding for the whole billing period
  4. The unprefixed fal_ai/gpt-image-2 alias logs the same keyed price instead of $0.00

How far you got

Config / setup the proxy ran with (env: FAL_AI_API_KEY and DATABASE_URL set, values redacted):

model_list:
  - model_name: gpt-image-2-fal
    litellm_params:
      model: fal_ai/openai/gpt-image-2
      api_key: os.environ/FAL_AI_API_KEY
  - model_name: gpt-image-2-fal-shortname
    litellm_params:
      model: fal_ai/gpt-image-2
      api_key: os.environ/FAL_AI_API_KEY
general_settings:
  master_key: sk-REDACTED

Version or commit: PR #37729 head f3896c0527b62f896f519be72a25f028856a9806 (the model only exists there, current main 500s on it)

Commands and their full output, up to the step that dead-ends:

$ curl -s http://127.0.0.1:16259/v1/images/generations -H "Authorization: Bearer sk-REDACTED" \
    -H "Content-Type: application/json" \
    -d '{"model": "gpt-image-2-fal", "prompt": "a lighthouse at dusk", "quality": "hd", "size": "1024x1024"}'
{"created": 1787266032, "data": [{"b64_json": null, "revised_prompt": null,
 "url": "https://v3b.fal.media/files/b/0aa726c0/FETroCyUVg5qIY6tnMDCi_SeslVLNw.png"}], ...}

$ psql -c 'SELECT "model", "call_type", "spend", "status" FROM "LiteLLM_SpendLogs" ORDER BY "startTime";'
fal_ai/openai/gpt-image-2 | aimage_generation | 0.145 | success   <-- the hd 1024x1024 call above
fal_ai/gpt-image-2        | aimage_generation | 0     | success   <-- the shortname alias call

What stopped me there: the request succeeds and returns a real image, but there is no way to make the logged spend follow the requested size and quality. The cost map only holds one scalar output_cost_per_image per model, so $0.145 is recorded for a call fal bills at $0.211, and the fal pricing page (https://fal.ai/models/openai/gpt-image-2) shows a different price per size/quality tier. The alias spelling logs $0.00 for a call fal charged real money for

What part of LiteLLM is this about?

Proxy cost tracking / model_prices_and_context_window.json

LiteLLM is hiring a founding backend engineer, are you interested in joining us and shipping to all our users?

No

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions