Hi, I’ve been using ChatGPT to help me make a Wordpress plugin that automatically adds alt-text to images when I upload them.
I think I’ve done everything I should have to reduce the size of the image being passed through - they’re 512px wide webp files. But each request is 8.5k tokens and from reading the documentation that seems too high. Maybe I’m misunderstanding the docs.
If I’m not and instead I’m doing something stupid I’d be very grateful for your help.
Here’s the extract of the php function that sends the request to the API:
function generate_alt_text_using_openai($image_url) {
$api_key = get_option('openai_api_key');
$request_body = json_encode(array(
'model' => 'gpt-4o-mini',
'messages' => [
[
'role' => 'user',
'content' => [
[
'type' => 'text',
'text' => 'Please generate an alt text for the image:'
],
[
'type' => 'image_url',
'image_url' => [
'url' => $image_url
]
]
]
]
],
'max_tokens' => 500,
));