Authenticate with a secret key and integrate Air API
This guide explains how to call Air API from your application after generating a secret key. Air API provides an OpenAI-compatible interface, allowing you to integrate with minimal code changes. If you are already using the OpenAI SDK, simply replace the base_url and API key.
If your application already uses the OpenAI SDK, you only need to update two settings.
# Before — OpenAIfrom openai import OpenAIclient = OpenAI(api_key="sk-...")# After — AirCloudfrom openai import OpenAIclient = OpenAI( api_key="YOUR_AIRCLOUD_API_KEY", # Replace with your AirCloud secret key base_url="YOUR_ENDPOINT" # Replace with your AirCloud endpoint)
// Before — OpenAIimport OpenAI from "openai";const client = new OpenAI({ apiKey: "sk-..." });// After — AirCloudimport OpenAI from "openai";const client = new OpenAI({ apiKey: "YOUR_AIRCLOUD_API_KEY", // Replace with your AirCloud secret key baseURL: "YOUR_ENDPOINT", // Replace with your AirCloud endpoint});
Select your API workload in the Console, then click View Code to view the endpoint URL and code samples for the selected model.Replace YOUR_ENDPOINT and YOUR_API_KEY in the sample code with the values from your Console.
Include your secret key in the Authorization header for every API request.
Authorization: Bearer YOUR_API_KEY
A secret key is displayed only once when it is created. We recommend storing it as an environment variable instead of hardcoding it in your source code. If you lose the key, generate a new one from the Console.
from openai import OpenAIclient = OpenAI( api_key="YOUR_API_KEY", base_url="YOUR_ENDPOINT")response = client.embeddings.create( model="YOUR_MODEL_ID", input="Convert this text into an embedding.")print(response.data[0].embedding)
import OpenAI from "openai";const client = new OpenAI({ apiKey: "YOUR_API_KEY", baseURL: "YOUR_ENDPOINT",});const response = await client.embeddings.create({ model: "YOUR_MODEL_ID", input: "Convert this text into an embedding.",});console.log(response.data[0].embedding);
curl -X POST YOUR_ENDPOINT/embeddings \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "YOUR_MODEL_ID", "input": "Convert this text into an embedding."}'
#!/bin/bashAPI_KEY="YOUR_API_KEY"response=$(curl -s -X POST YOUR_ENDPOINT/embeddings \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "YOUR_MODEL_ID", "input": "Convert this text into an embedding."}')echo "$response" | jq .