Is the cost of transferring images through base64 and URL the same?

For a picture, I calculate the pixels to be 1900*1900 / / 223KB.

  1. The cost of using URL to transfer is US$0.003825, by gpt price. But I have not successfully transferred to GPT. So there’s no way to know the actual cost at this time.
  2. I have used base64 encoding for transmission and consumed more than 100,000 tokens.

Can someone tell me, does both transfer methods cost the same?

Do you have a screenshot of 100,000 tokens consumed due to base64 encoding?

Sorry, I uploaded it a few days ago. Records in PYcharm are not retained. But I have a situation of API consumption. I spent nearly $5 that day. Since I’m a beginner, I had GPT return records that consumed a tonken of proficiency.

on 19 Jun, when I first upload the file, it prompts me for more than a single transfer token. So I divided the base64 encoding into about 30 parts for transmission. The base64 encoding of an image is divided into 30 parts.

Make sure you did not send the base64-encoded string as-is as a user message.

This is what happens when a user sends a base64 encoded image as text rather than as an image URL.

There have been a few reports of this the last few weeks.

1 Like

You are indeed an expert. That’s what I do.
Please tell me what is the correct way to do this?

That’s what I do.
I have never learned any programming , so I wrote the codes with GPT guidance. Although I made this mistake, I still want to say that GPT is a great project.

I am not an expert, but…

You can call it correctly by replacing image_path in the code shown below with the path to your local image and api_key with your actual API key.

really thanks. Done it with base64 .and token takes about 3K which upload a2152*3029 PNG .

thanks again!

1 Like

A bit late to answer, but in case someone comes across this post in the future:

In my tests, the cost of tokens when using base64 for input images was very different from the cost mentioned in the pricing calculator at https://openai.com/api/pricing/

After searching for a while, I found that in the documentation there is an example for input images, using the API itself to store an image and get its ID. So, in your query, just point to this ID instead of base64

I hope I helped someone :slight_smile:

from openai import OpenAI

client = OpenAI()

# Function to create a file with the Files API
def create_file(file_path):
  with open(file_path, "rb") as file_content:
    result = client.files.create(
        file=file_content,
        purpose="vision",
    )
    return result.id

# Getting the file ID
file_id = create_file("path_to_your_image.jpg")

response = client.responses.create(
    model="gpt-4.1-mini",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "what's in this image?"},
            {
                "type": "input_image",
                "file_id": file_id,
            },
        ],
    }],
)

print(response.output_text)