Skip to content

Authentication

Secure access to the Mira API requires authentication. This guide provides information on how to authenticate your API requests using API keys. Ensuring that your API interactions are secure helps protect your data and services from unauthorized access.

Using API Keys

API keys are the primary method for authenticating with the Mira API. They provide a simple yet secure way to control access to your Mira services.

Obtaining an API Key

  1. Create an Account: Sign up for an account on the Mira platform if you haven't done so already. Visit https://console.mira.network/signup to register.
  2. Generate API Key: Once logged in, navigate to the API section in your dashboard. There, you can generate a new API key. Keep this key secure as it provides access to your Mira services.

Managing API Keys

  • Keep your keys secret: Do not share your API keys in publicly accessible areas such as GitHub, client-side code, or forums.
  • Regenerate keys if compromised: If you believe an API key has been compromised, regenerate it immediately to prevent unauthorized use.
  • Limit usage: Use key restrictions to limit the scope and usage of each key if possible, reducing potential damage from key compromise.

Making Authenticated Requests

To make an authenticated request to the Mira API, you need to include your API key in the request headers. Here is how you can do this:

Example with curl

bash
curl -X POST https://console.mira.network/v1/@klok/qna \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "What is the capital of France?"}'

Example in Node.js

Using the Axios library to make authenticated requests:

javascript
import axios from "axios";

const API_KEY = "YOUR_API_KEY"; // replace YOUR_API_TOBE with your actual API key
const url = "https://console.mira.network/v1/@klok/qna";

axios
  .post(
    url,
    {
      query: "What is the capital of France?",
    },
    {
      headers: {
        Authorization: `Bearer ${API_KEY}`,
      },
    }
  )
  .then((response) => console.log(response.data))
  .catch((error) => console.error("Error:", error));

Example in Python

Using the requests library to send authenticated requests:

python
import requests

API_KEY = 'YOUR_API_KEY'  # replace YOUR_API_KEY with your actual API key
url = 'https://console.mira.network/v1/@klok/qna'

headers = {
    'Authorization': f'Bearer {API_KEY}',
    'Content-Type': 'application/json',
}

data = {
    "query": "What is the capital of France?"
}

response = requests.post(url, headers=headers, json=data)
print(response.text)

Conclusion

Authenticating your API requests ensures that your interactions with the Mira API are secure. By following the guidelines provided above, you can protect your API keys and ensure that your applications communicate with Mira services safely and effectively.