Generating image descriptions using Claude
Use image description to generate alt text and visual summaries from images.
Common use cases include:
- Accessibility workflows for screen readers
- Digital asset cataloging
- Document enrichment for scanned reports
- E-learning content description
- Archive and metadata generation
This guide uses Claude as the VLM provider through Nutrient Vision API.
Download sampleHow Nutrient helps
Nutrient Java SDK handles provider configuration, request handling, and response parsing.
The SDK handles:
- VLM API authentication, endpoint configuration, and request formatting
- Image encoding and multimodal API request structures
- Model parameters such as temperature, max tokens, and provider-specific settings
- Vision service failures and API rate limits
Complete implementation
This example generates an image description using Claude:
package io.nutrient.Sample;Import the required classes and define the sample class:
import io.nutrient.sdk.Document;import io.nutrient.sdk.Vision;import io.nutrient.sdk.enums.VlmProvider;import io.nutrient.sdk.exceptions.NutrientException;import io.nutrient.sdk.settings.ClaudeApiSettings;import io.nutrient.sdk.settings.VisionSettings;
import java.io.FileWriter;import java.io.IOException;
public class DescribeImageWithClaude {Configuring the Claude provider
Create the main method, open the image in try-with-resources, and configure Claude.
In this sample:
setProvider(VlmProvider.Claude)selects Claude.setApiKey("CLAUDE_API_KEY")sets the Anthropic API key.- Input can be PNG, JPEG, GIF, BMP, or TIFF.
public static void main(String[] args) throws NutrientException, IOException {Creating a vision instance and generating the description
Create a vision instance and call describe() to generate text.
In this sample:
Vision.set(document)binds processing to the opened image.vision.describe()returns a description string.- The SDK handles encoding, request construction, and response parsing.
try (Document document = Document.open("input_photo.png")) { // Configure Claude as the VLM provider VisionSettings visionSettings = document.getSettings().getVisionSettings(); visionSettings.setProvider(VlmProvider.Claude);
// Set the Claude API key ClaudeApiSettings claudeSettings = document.getSettings().getClaudeApiSettings(); claudeSettings.setApiKey("CLAUDE_API_KEY");Saving the description
Write the description to a text file.
This sample uses try-with-resources for both document and file writer cleanup:
Vision vision = Vision.set(document); String description = vision.describe(); try (FileWriter writer = new FileWriter("output.txt")) { writer.write(description); } } }}Understanding the output
describe() returns natural language text for accessibility and content understanding.
Claude descriptions are typically:
- Concise — Focused on key subjects and details, often one to three sentences
- Accessible — Suitable for users who rely on screen readers
- Accurate — Based on visible content only
- Contextual — Include relevant relationships and scene context
Use this output for accessibility metadata, image search, and document workflows.
Claude API settings
The Claude provider uses these ClaudeApiSettings properties:
ApiEndpoint— The Claude API endpoint (default:https://api.anthropic.com/v1/).ApiKey— Your Anthropic API key for authentication.Model— The model identifier to use (default:claude-sonnet-4-5).Temperature— Controls response creativity (0.0 = deterministic, 1.0 = creative).MaxTokens— Maximum tokens in the response (default: 16384).
Error handling
The sample can throw:
NutrientExceptionfor vision and API issuesIOExceptionfor file I/O operations
Common failure scenarios include:
- The input image can’t be read due to path, permission, or format issues
- The Claude API key is missing or invalid
- The Claude API is unavailable
- Rate limits are exceeded
- Network requests fail before reaching the API
- Image data is too large or corrupted
- File writing fails due to path, disk, or permission issues
In production code:
- Catch
NutrientExceptionandIOException. - Return clear error messages.
- Log failure details for debugging.
- Add retry logic for transient API failures.
Conclusion
Use this workflow to generate image descriptions with Claude:
- Open the image file using try-with-resources for automatic resource cleanup.
- The SDK supports multiple image formats, including PNG, JPEG, GIF, BMP, and TIFF.
- Retrieve the vision settings with
document.getSettings().getVisionSettings()to configure the VLM provider. - Set the provider to Claude with
setProvider(VlmProvider.Claude)instead of alternatives like OpenAI or local models. - Retrieve Claude-specific settings with
document.getSettings().getClaudeApiSettings()for API configuration. - Set the Anthropic API key with
setApiKey()using credentials obtained from the Anthropic Console. - Claude API settings control endpoint URLs, model selection (default: claude-sonnet-4-5), temperature, and max tokens.
- Create a vision instance with
Vision.set()bound to the document with configured provider settings. - Generate the description with
vision.describe(), which sends the image to Claude’s vision endpoint and returns natural language text. - The SDK encodes image data, constructs multimodal API requests, and parses responses automatically.
- Generated descriptions are concise (1–3 sentences), accessible (WCAG-compliant alt text), accurate (observable details only), and contextual.
- Write the description to a file using try-with-resources with
FileWriterfor automatic resource cleanup. - Handle
NutrientExceptionfor vision processing failures, including authentication errors, API failures, and rate limits. - Handle
IOExceptionfor file operations, including read failures or write errors when saving output.
For related image workflows, refer to the Java SDK guides.
Download this ready-to-use sample package to explore Claude-based image description.