Can someone explain me why I need to pay so much money for a single request? The API calculator showned me that it should cost less than 5 cents
I am submitting an image file with less than 200kb in size and a variaton less than 2k square resolution
def analyze_chart_with_gpt4o(image_path):
base64_image = encode_image(image_path)
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{"type": "text",
"text": "Analyze this chart with listed / bulletpointed keypoints and price targets. Keep it within 250 characters and use a casual tone."},
{"type": "text", "text": f"data:image/jpeg;base64,{base64_image[:50000]}"}
# Truncate the base64 string to avoid context length issues
]
}
],
"max_tokens": 1500
}
try:
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
response_json = response.json()
logger.debug(f"API Response: {response_json}")
if 'choices' in response_json and len(response_json['choices']) > 0:
return response_json['choices'][0]['message']['content']
else:
logger.error(f"Unexpected API response structure: {response_json}")
return "GPT-4o analysis unavailable due to an unexpected response structure."
except requests.exceptions.HTTPError as http_err:
logger.error(f"HTTP error occurred: {http_err}")
logger.error(f"Response content: {response.content}")
return "GPT-4o analysis unavailable due to a request error."
except requests.exceptions.RequestException as req_err:
logger.error(f"Request error occurred: {req_err}")
return "GPT-4o analysis unavailable due to a request error."