hammer-brushSupported SDKs [OLD]

This page describes the SDKs that can be used to call our API.

Comparing requests made with different SDKs, pay attention to the following common aspects across all SDKs:

  • how the Authorization header and the AIML API key are provided,

  • how the POST method and the endpoint URL are specified,

  • how the input parameters are passed.

circle-check

REST API

This SDK is simple to use, and the required requests library is commonly preinstalled in many environments. Therefore, this SDK is used in the documentation examples for all of our models.

Authorization

Our API authorization is based on a Bearer token. Include it in the Authorization HTTP header within the request. Example:

  headers: {
    Authorization: "Bearer <YOUR_AIMLAPI_KEY>",
  },

Request Example

fetch("https://api.aimlapi.com/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer <YOUR_AIMLAPI_KEY>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "gpt-4o",
    messages: [
      {
        role: "user",
        content: "What kind of model are you?",
      },
    ],
    max_tokens: 512,
  }),
})
  .then((res) => res.json())
  .then(console.log);

OpenAI

The OpenAI SDK is a nice module that allows us to use the AI/ML API without dealing with repetitive boilerplate code for handling cURL requests.

In the setting up articlearrow-up-right, we showed an example of how to use the OpenAI SDK with the AI/ML API. We configured the environment from the very beginning and executed our request to the AI/ML API.

chevron-rightThe AI features that the OpenAI SDK supportshashtag
  • Streaming

  • Completions

  • Chat Completions

  • Audio

  • Beta Assistants

  • Beta Threads

  • Embeddings

  • Image Generation

  • File Uploads

Example Code


AI/ML API Python library

We have started developing our own SDK to simplify the use of our service. Currently, it supports only chat completion and embedding models.

circle-check

Installation

After obtaining your AIML API key, create an .env file and copy the required contents into it.

Copy the code below, paste it into your .env file, and set your API key in AIML_API_KEY="<YOUR_AIMLAPI_KEY>", replacing <YOUR_AIMLAPI_KEY> with your actual key:

Install aiml_api package:

Request Example

To execute the script, use:


Next Steps

Last updated

Was this helpful?