API Authentication

This article introduces the authentication methods for using the MaiAgent API and how to obtain them

MaiAgent uses API keys for authentication.

Authentication Method

All API requests must include an API Key in the HTTP Header, in the following format:

const headers = {
  "Authorization": "Api-Key YOUR_API_KEY_HERE",
  "Content-Type": "application/json"
}

How to Obtain an API Key?

Please log in to the MaiAgent system backend and follow these steps:

  1. Click the "Username" dropdown menu in the upper right corner.

  2. Click "Account" to go to the profile page.

  1. Switch the page to the API Key page.

  1. You can then copy and view the "API Key".

Error Handling

When authentication fails, the API will return a 401 Unauthorized HTTP error code:

  • Invalid or Missing API Key

{
  "detail": "Authentication credentials were not provided."
}

Fix suggestion: Check if the request header contains the correct Authorization field. The format should be: Authorization: Api-Key YOUR_API_KEY

  • Incorrect API Key Format

{
  "detail": "Invalid API key format."
}

Fix suggestion: Confirm that the API Key format is correct. Check if the correct prefix Api-Key is used instead of Bearer, and ensure the API Key itself does not have extra spaces or characters.

Last updated

Was this helpful?