This guide helps you migrate from the old exif-ai API to the new, improved API design.
The new API provides three usage patterns while maintaining full backward compatibility:
- Simple API -
processImage()for common use cases - Fluent Builder API -
new ExifAI()for readable, chainable code - Advanced API -
processImageAdvanced()for complex configurations - Legacy API -
execute()still works (no changes needed)
# Old way - still supported
exif-ai -i photo.jpg -a ollama -T description -v -d
exif-ai -i photo.jpg -a openai -m gpt-4o -p "Custom prompt"# New way - cleaner and more intuitive
exif-ai photo.jpg --provider ollama --tasks description --verbose --dry-run
exif-ai photo.jpg --provider openai --model gpt-4o --description-prompt "Custom prompt"- Positional argument: Image path is now a positional argument
- Better option names:
--providerinstead of-a/--api-provider - Clearer flags:
--dry-runinstead of-d,--verboseinstead of-v - Grouped help: Options are organized in logical groups
- Examples in help: Built-in examples with
--help
Before (Old API):
import { execute } from "exif-ai";
await execute({
path: "photo.jpg",
provider: "ollama",
tasks: ["description"],
dry: true,
verbose: true
});After (New Simple API):
import { processImage } from "exif-ai";
await processImage({
image: "photo.jpg",
provider: "ollama",
tasks: ["description"],
preview: true,
verbose: true
});Before (Old API):
import { execute } from "exif-ai";
await execute({
path: "photo.jpg",
provider: "openai",
model: "gpt-4o",
tasks: ["description", "tag"],
descriptionPrompt: "Describe this image",
tagPrompt: "Generate tags",
descriptionTags: ["XPComment", "Description"],
tagTags: ["Subject", "Keywords"],
verbose: true,
dry: false,
avoidOverwrite: true,
repeat: 2
});After (New Fluent API):
import { ExifAI } from "exif-ai";
await new ExifAI("photo.jpg")
.provider("openai")
.model("gpt-4o")
.tasks("description", "tag")
.descriptionPrompt("Describe this image")
.tagPrompt("Generate tags")
.descriptionTags("XPComment", "Description")
.tagTags("Subject", "Keywords")
.verbose()
.skipExisting()
.retries(2)
.run();Or (New Advanced API):
import { processImageAdvanced } from "exif-ai";
await processImageAdvanced({
image: "photo.jpg",
ai: {
provider: "openai",
model: "gpt-4o",
descriptionPrompt: "Describe this image",
tagPrompt: "Generate tags"
},
exif: {
descriptionTags: ["XPComment", "Description"],
tagTags: ["Subject", "Keywords"]
},
options: {
tasks: ["description", "tag"],
verbose: true,
skipExisting: true,
retries: 2
}
});| Old Parameter | New Parameter | Notes |
|---|---|---|
path |
image |
More descriptive |
dry |
preview |
Clearer intent |
avoidOverwrite |
skipExisting |
More intuitive |
repeat |
retries |
Standard terminology |
writeArgs |
exifArgs |
Shorter name |
Your existing code will continue to work without any changes. The old execute() function and CLI syntax are fully supported.
Migrate new code to use the new API while keeping existing code unchanged:
// Existing code - keep as is
import { execute } from "exif-ai";
// New code - use new API
import { processImage, ExifAI } from "exif-ai";Update all code to use the new API for consistency:
- Replace
execute()calls with appropriate new API - Update parameter names where needed
- Consider using the fluent API for better readability
- Clearer syntax: More intuitive command structure
- Better help: Organized options with examples
- Shorter commands: Less typing for common operations
- Better TypeScript support: Improved type definitions
- Multiple API styles: Choose what fits your use case
- Fluent interface: More readable code
- Better error messages: Clearer error reporting
// Simple: Just process an image
await processImage({
image: "photo.jpg",
provider: "ollama"
});
// Fluent: Chain operations
await new ExifAI("photo.jpg")
.provider("openai")
.model("gpt-4o")
.preview()
.run();
// Advanced: Full control
await processImageAdvanced({
image: "photo.jpg",
ai: { provider: "google", model: "gemini-1.5-pro" },
options: { tasks: ["description"], preview: true }
});- Check the updated README.md for comprehensive examples
- Run
exif-ai --helpto see the new CLI options - Look at
examples/new-api-examples.jsfor working code samples - The old API documentation is still valid for the
execute()function
We maintain full backward compatibility:
- All existing CLI commands work unchanged
- The
execute()function works exactly as before - No breaking changes to existing functionality
- Old parameter names are still supported
You can migrate at your own pace or not at all - your choice!