Skip to content

Quickstart

This guide will help you make your first request to the CompactifAI API in minutes.

Before you begin, you’ll need:

  • A CompactifAI API key. Please see our authentication guide for more information.
  • We expose a REST API, so you can use any language that can make HTTP requests. We provide examples in cURL, Python, and JavaScript but feel free to use whatever you’re comfortable with.

All requests to the CompactifAI API require an API key for authentication. If you don’t have an API key yet, see our authentication guide.

Include your API key in the header of all requests:

Authentication Header
Authorization: Bearer YOUR_API_KEY

Let’s make a simple request to the Chat Completions API:

cURL
curl https://api.compactif.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "cai-llama-3-1-8b-slim",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, how are you?"}
]
}'

The API will return a response like this:

API Response
{
"id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
"object": "chat.completion",
"created": 1749600000,
"model": "cai-llama-3-1-8b-slim",
"choices": [
{
"message": {
"role": "assistant",
"content": "Hello! I'm doing well, thank you for asking. I'm an AI assistant created by CompactifAI. How can I help you today?"
},
"finish_reason": "stop",
"index": 0
}
],
"usage": {
"prompt_tokens": 23,
"completion_tokens": 28,
"total_tokens": 51
}
}

Now that you’ve made your first API call, you can: