First API Call
Now, let's use your key to interact with an AI model. Our API is compatible with the OpenAI SDK, making integration incredibly simple.
Installation
First, make sure you have the necessary library for your programming language.
- Python
- Node.js
pip install openai
npm install openai
Code Example
Use the following code snippet to send a request. Remember to replace YOUR_API_KEY
with the key you just created.
- Python
- Node.js
- cURL
from openai import OpenAI
# Initialize the client
client = OpenAI(
base_url='https://api.naga.ac/v1',
api_key='YOUR_API_KEY' # 🐲 Your NagaAI API key
)
# Create the chat completion request
response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[{'role': 'user', 'content': "What is the capital of France?"}]
)
# Print the response
print(response.choices[0].message.content)
import OpenAI from 'openai';
// Initialize the client
const client = new OpenAI({
baseURL: 'https://api.naga.ac/v1',
apiKey: 'YOUR_API_KEY', // 🐲 Your NagaAI API key
});
async function main() {
// Create the chat completion request
const response = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: "What is the capital of France?" }],
});
// Print the response
console.log(response.choices[0].message.content);
}
main();
curl https://api.naga.ac/v1/chat/completions \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer YOUR_API_KEY" \\
-d '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'
If everything is correct, you should receive a response like: The capital of France is Paris.
For More Examples
Looking for more? Check out our Code Examples for more advanced use cases.