Image Tokens: From 256 to 1792
On this page
How images consume tokens
When you send an image to Grok, it converts into tokens before the model analyzes it. Unlike text, where a token roughly corresponds to a word, image tokens depend on the image size and the requested level of detail.
Understanding this mechanism is essential for anticipating costs and sizing your requests.
The range: 256 to 1792 tokens
Each image sent to the API consumes between 256 and 1792 tokens. This significant variation comes down to several factors:
- Image resolution: a 256x256 pixel image consumes fewer tokens than a 4096x4096 image
- The
detailparameter:lowconsumes the minimum,highconsumes the maximum - Image content: a complex image with many details can result in higher consumption in
automode
Tracking token consumption
The xAI API provides a precise count of image tokens in the response. You’ll find it in the usage field:
{
"usage": {
"prompt_tokens": 2048,
"completion_tokens": 150,
"total_tokens": 2198,
"prompt_tokens_details": {
"image_tokens": 1024,
"text_tokens": 1024
}
}
}
The prompt_tokens_details.image_tokens field tells you exactly how many tokens the images in your request consumed. This is an indispensable tool for monitoring your costs in production.
Impact of detail level on tokens
The detail parameter is the main lever for controlling image token consumption:
# Same image, very different token results
# detail: low → ~256 image tokens
# detail: auto → ~512-1024 image tokens (variable)
# detail: high → ~1024-1792 image tokens
In low mode, the image resizes to a reduced resolution before analysis. The model receives less information but consumes significantly fewer tokens.
In high mode, the image splits into high-resolution tiles. Each tile analyzes separately, which multiplies the number of tokens but allows the model to read fine text or detect subtle details.
Calculating the cost of a multimodal request
To estimate the cost of a request with images, combine text and image tokens:
def estimate_cost(num_images, detail="auto", text_tokens=500):
# Estimate image tokens by level
image_tokens = {
"low": 256,
"auto": 768, # estimated average
"high": 1536 # estimated average
}
total_image = num_images * image_tokens[detail]
total = total_image + text_tokens
# Indicative price per million tokens (input)
price_per_million = 2.00 # grok-4.5 input — check current pricing schedule
cost = (total / 1_000_000) * price_per_million
return {
"image_tokens": total_image,
"text_tokens": text_tokens,
"total_tokens": total,
"estimated_cost": f"${cost:.4f}"
}
Optimizing token consumption
Resize before sending
If your image is very large but you don’t need the maximum resolution, resize it before sending:
from PIL import Image
import io
import base64
def optimize_image(path, max_size=(1024, 1024)):
img = Image.open(path)
img.thumbnail(max_size)
buffer = io.BytesIO()
img.save(buffer, format="JPEG", quality=85)
buffer.seek(0)
encoded = base64.standard_b64encode(buffer.read()).decode()
return f"data:image/jpeg;base64,{encoded}"
Choose the right format
- JPEG: lighter, ideal for photos and images with many colors
- PNG: heavier but lossless, suited for screenshots and diagrams with text
Group intelligently
If you analyze a batch of images, group those requiring the same detail level into separate requests rather than mixing low and high in a single request.
Monitoring in production
In production, systematically log image tokens to detect spikes:
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": url},
{"type": "input_text", "text": prompt}
]
)
# Log tokens
usage = response.usage
print(f"Image tokens : {usage.prompt_tokens_details.image_tokens}")
print(f"Text tokens : {usage.prompt_tokens_details.text_tokens}")
print(f"Total prompt : {usage.prompt_tokens}")
Pricing as of August 5, 2026 — prices change regularly: before any budget calculation, check the current pricing schedule on the official xAI models and pricing page.
Key takeaways
- Images consume between 256 and 1792 tokens depending on their size and detail level
- The
prompt_tokens_details.image_tokensfield gives the exact count - The
detailparameter is the main lever for controlling consumption - Resizing images before sending reduces tokens without sacrificing quality for simple tasks
- Monitor image tokens in production to anticipate costs