How to send a request to the API?

To interact with our API, follow these steps:

  1. Obtain an API Key
    • Log in to your account and retrieve your API key from the dashboard
  2. Set Up Your Environment
    • Ensure you have the required libraries installed. For Python, you can install requests if it is not already available:
pip install requests
  1. Send a Request
  • Choose the right HTTP method. Most requests use POST, while GET is used to retrieve generated audio or video via generation ID
  • Set the endpoint. Base URL can be either https://api.aimlapi.com or https://api.aimlapi.com/v1. To find the full endpoint, search for the needed model in our documentation
  • Set the headers. 2 headers are needed - Authorization and Content-Type. The values should be in the following format:
"Authorization" : "Bearer {YOUR_API_KEY}",
"Content-Type" : "application/json"
  • Add the Request Body. This is where you set parameters and prompts for the model. To determine which parameters a model requires or supports, check its API Schema in the documentation

  1. Process the Response
    • The API returns a JSON response, which you can parse and use in your application.

Example Request in Python

import requests

response = requests.post(
    "https://api.aimlapi.com/v1/chat/completions",
    headers={"Content-Type":"application/json", "Authorization": "Bearer 'YOUR_API_KEY'"},
    json={"model":"o1","messages":[{"role":"user","content":"Who are you"}]}
)
data = response.json()
print(data)
 

For more details on available endpoints, parameters, and response formats, refer to our API Documentation. If you need further assistance, contact our support team.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us