Image Caption API - Ruby Gem

Image Caption is an AI-powered tool that generates descriptive captions for images. Simply upload an image and receive a natural language description of its contents.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_imagecaption'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_imagecaption

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_imagecaption'

# Initialize the client
client = APIVerve::Imagecaption::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({ image: "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/640px-Cat03.jpg" })

# Print the response
puts response

File Upload

# Upload a file
response = client.execute_with_file("/path/to/file.jpg")

# Or use a URL
response = client.execute_with_url("https://example.com/image.jpg")

Error Handling

begin
  response = client.execute({ image: "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/640px-Cat03.jpg" })
  puts response["data"]
rescue APIVerve::Imagecaption::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Imagecaption::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Imagecaption::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "caption": "A golden retriever running through a grassy field on a sunny day"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.