Authentication: Using API Keys

This document will guide you on how to obtain your API keys, consisting of the Bearer auth token and the x-api-key, and how to use them to make API requests on our platform.

1. Obtaining API Keys

To obtain both the Bearer auth token and the x-api-key, you will need to follow the steps below:

  1. Login to your account on our platform. If you do not have an account, please sign up.

  2. Once you are logged in, go to "Auth Keys" section.

  3. In the "Auth Keys" section, click on "Generate new key" button.

  4. Next, it will prompt you to enter an identifier. This identifier can be any name of your choice and will be used to identify this specific tokens.

  5. After entering your chosen identifier, click on the "Generate" button.

  6. Upon clicking the button, the system will generate both your Bearer auth token and x-api-key.

  7. These keys will be displayed on the screen. Copy both keys or click on "Download JSON" button to download the keys in a JSON file.

  8. Store them in a secure location. Remember, these keys grant access to your account and should be treated with the same level of security as your password.

2. Using API Keys to Send API Requests

Both the Bearer auth token and the x-api-key are required in all requests to our API. They need to be passed in the headers of your HTTP requests. Here is an example of how to do this:

curl -X GET "https://api.yourplatform.com/endpoint" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN" \
-H "x-api-key: YOUR_X_API_KEY"

Replace YOUR_BEARER_TOKEN and YOUR_X_API_KEY with your actual Bearer auth token and x-api-key respectively.

Here's a quick text to image API example if you're using a programming language like Python:

Send request API:

import requests
import json

headers = {
  'Authorization': 'Bearer YOUR_BEARER_TOKEN',
  'x-api-key': 'YOUR_X_API_KEY',
  'Content-Type': 'application/json'
}

url = "https://api.monsterapi.ai/apis/add-task"

payload = json.dumps({
  "model": "txt2img",
  "data": {
    "prompt": "highly detailed photo of Lionel Messi",
    "negprompt": "",
    "samples": 1,
    "steps": 50,
    "aspect_ratio": "square",
    "guidance_scale": 12.5,
    "seed": 2321
  }
})


response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
# This returns a process id which will be used in next API to get status

Fetch request status API:

import requests
import json

headers = {
  'Authorization': 'Bearer YOUR_BEARER_TOKEN',
  'x-api-key': 'YOUR_X_API_KEY',
  'Content-Type': 'application/json'
}
url = "https://api.monsterapi.ai/apis/task-status"

payload = json.dumps({
  "process_id": process_id
})

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Again, in both the APIs replace YOUR_BEARER_TOKEN and YOUR_X_API_KEY with your actual keys.

All API calls made without a valid Bearer auth token and x-api-key will result in an error message.

If you lose or forget your keys, you can generate new ones by repeating the steps mentioned above in the 'Obtaining API Keys' section.

Keep your keys secure at all times to prevent unauthorized access to your account.

For any queries please reach out to us at support@monsterapi.ai

Last updated