Getting Started

Learn how to create an API key and make an API call to generate an image, including webhook setup.

Introduction

This guide will walk you through the process of creating an API key, making an API call to generate an image, and setting up webhooks for notifications in your backend project.

Prerequisites

Before proceeding, ensure you have the following:

  • A running instance of the backend server.
  • Access to the server's environment variables for configuration.

Creating an API Key

To interact with the API, you need to create an API key. Follow these steps:

  1. Access the API Key Management Interface:

    Log in to your backend server's management interface.

  2. Create a New API Key:

    Navigate to the API Key section and click on "Create New API Key". Provide a name for your API key and associate it with your user account.

  3. Save the API Key:

    Once generated, save the API key securely. You will use this key to authenticate your API requests.

Making an API Call to Create an Image

With your API key ready, you can now make an API call to generate an image. Here's how:

  1. Set Up Your Request:

    Use a tool like curl, Postman, or fetch in Node.js to set up your API request. Ensure you include the API key in the request headers for authentication.

  2. Define the Request Payload:

    Your request should include the necessary fields, such as the image prompt and any additional parameters required by the API.

    Example payload:

    {
       "model" : "playground-v2",
       "input" : {
         "prompt" : "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
       },
       "webhook" : "https://your-server.com/api/webhook"
    }
    
  3. Send the Request:

    Send the request to the API endpoint responsible for image creation. Wait for the response, which will include the image URL or an error message.

    Example using fetch in Node.js:

    const fetch = require('node-fetch');
    
    const createImage = async () => {
      const response = await fetch('https://api.artificialstudio.ai/api/generate', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'YOUR_API_KEY'
        },
        body: {
          model: "playground-v2",
          input: {
            prompt : "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
          },
          webhook: "https://your-server.com/api/webhook"
        }
      });
    
      const data = await response.json();
      console.log(data);
    };
    
    createImage();
    

Setting Up Webhooks

Webhooks allow you to receive notifications about the status of your image creation. Follow these steps to set up webhooks:

  1. Configure Webhook URL:

    In your API request, include a webhook field with the URL where you want to receive notifications.

  2. Handle Webhook Notifications:

    Ensure your server is set up to handle incoming webhook requests. The webhook payload will include details about the image creation status and any errors encountered.

    Example webhook payload:

    {
      "_id": "media_id",
      "status": "success",
      "output": "https://files.artificialstudio.ai/...",
      "model": "model_slug",
      "type": "image",
      "payload": {
        "prompt": "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
      },
      "error": null
    }
    
  3. Verify Webhook Data:

    For security, verify the data received in the webhook to ensure it originates from your backend server.

    Example using Express:

    app.post("/api/webhook", (req, res) => {
      console.log(req.body);
      res.send("Webhook received");
    });
    

Conclusion

You are now ready to create API keys, make API calls to generate images, and set up webhooks for notifications. For further assistance, refer to the API Documentation or contact support.