Skip to content

Bug: OpenAI image spans price only one image when n > 1 #1933

Open

Description

@anubhavlal07

Component

OpenLIT Python SDK (openlit.instrumentation.openai, common_image_logic)

What happened?

common_image_logic in sdk/python/src/openlit/instrumentation/openai/utils.py computes gen_ai.usage.cost as get_image_model_cost(model, pricing, size, quality). That is the price of a single image. The request's n and the number of images in response.data are ignored. OpenAI bills per image, so images.generate(n=4) reports 1/4 of the real cost, both on the span and on the gen_ai.usage.cost metric. The same function also backs images.edit and images.create_variation.

The Together image path already multiplies by the number of returned images (len(scope._response_data) * cost).

Steps to reproduce

import openlit, openai
openlit.init()
openai.OpenAI().images.generate(model="dall-e-2", prompt="a cat", n=4, size="1024x1024")

Expected

gen_ai.usage.cost = 4 x 0.02 = 0.08

Actual

gen_ai.usage.cost = 0.02

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions