Code Examples

To help you get started with integrating the ForVoyez API into your application, we provide code examples in various programming languages. These examples demonstrate how to make a request to the /describe endpoint to generate metadata for an image, and to the /tokens endpoint to check an API key.

Run these examples on your server, never in a web page: an API key sent to a browser can be read and used by anyone. To analyse images that your visitors upload, send them to your server first and call the ForVoyez API from there. The JavaScript examples are for Node.js 20 or later (save them as .mjs files) and read your API key from the FORVOYEZ_API_KEY environment variable.

Generating Metadata for an Image

curl -X POST \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "image=@/path/to/your/image.jpg" \
  -F "schema={\"title\":\"A short title for the image\",\"alternativeText\":\"Alt text for screen readers\",\"caption\":\"A one-sentence caption\"}" \
  -F "keywords=playful,kittens" \
  -F "context=Playful kittens" \
  -F "language=en" \
  https://forvoyez.com/api/describe

These code examples demonstrate how to make a POST request to the /describe endpoint using different programming languages. Make sure to replace YOUR_API_KEY with your actual API key (or set the FORVOYEZ_API_KEY environment variable for the JavaScript example) and provide the path to your image file.

The request includes the following parameters:

  • image: The image file (required)
  • schema: JSON string with a flat object mapping each output field to a description (optional)
  • keywords: Comma-separated list of keywords (optional)
  • context: Additional context about the image (optional)
  • language: Desired language for the output (optional, defaults to 'en')

For more detailed information on the request parameters and response format, refer to the /describe endpoint documentation.

Checking an API Key and Your Credits

A GET request to the /tokens endpoint checks an API key and returns the credit balance of its account. It uses no credit.

curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://forvoyez.com/api/tokens

See the /tokens endpoint documentation for all the fields of the response and its error messages.

Next Steps

  • Explore the API Reference for detailed information on all available endpoints and their parameters.
  • Integrate the ForVoyez API into your application using your preferred programming language, from your server.
  • If you encounter any issues or have questions, consult the Error Codes documentation or reach out to our support team for assistance.

Start generating metadata for your images with the ForVoyez API and enhance your application's functionality!