Skip to content

Text Generation

CompactifAI API offers powerful text generation capabilities through our completion endpoints. Our compressed models can generate coherent, contextually relevant text for a wide range of applications while offering significant cost and performance advantages over uncompressed alternatives.

import requests
API_URL = "https://api.compactif.ai/v1/completions"
API_KEY = "your_api_key_here"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
data = {
"model": "cai-llama-4-scout-slim",
"prompt": "Write a short story about a robot that learns to paint:",
"max_tokens": 250,
"temperature": 0.7
}
response = requests.post(API_URL, headers=headers, json=data)
print(response.json()["choices"][0]["text"])
ParameterTypeDescription
modelstringID of the compressed model to use
promptstringThe prompt to generate completions for
max_tokensintegerMaximum number of tokens to generate
temperaturenumberControls randomness (0-2)
top_pnumberControls diversity via nucleus sampling
nintegerNumber of completions to generate
stopstring or arraySequences where the API will stop generating
toolsarrayList of tools the model may call during generation
tool_choicestringControls tool usage ("auto", "none","required", or specific function)

Please refer to our API Reference or the OpenAI API reference for more information on the parameters.