How to send a request to the API?
To interact with our API, follow these steps:
- Obtain an API Key
- Log in to your account and retrieve your API key from the dashboard
- Set Up Your Environment
- Ensure you have the required libraries installed. For Python, you can install
requests
if it is not already available:
- Ensure you have the required libraries installed. For Python, you can install
pip install requests
- Send a Request
- Choose the right HTTP method. Most requests use
POST
, whileGET
is used to retrieve generated audio or video via generation ID - Set the endpoint. Base URL can be either
https://api.aimlapi.com
orhttps://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
- 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.