API Documentation

Simple and free LLM API. Get started in minutes with unlimited usage.

🔑 Get API Key & Examples

Free Usage

✨ Completely Free

  • • No registration required
  • • Unlimited API calls
  • • No rate limits
  • • No credit card needed

We believe AI should be accessible to everyone. Our service is completely free - just generate an API key and start building!

Token Limits

Current Token Limits

Input Text: Up to 200,000 characters (~50,000 tokens)

Output Response: Up to 16,384 tokens (~65,000 characters)

Token Warning System

When your input approaches token limits, you'll receive automatic warnings:

  • Chat interface displays warnings when limits are exceeded
  • API responses include token count information
  • Requests exceeding limits are automatically truncated for processing

Chat Endpoint

POSThttps://apifreellm.com/api/chat

Request Body:

{
  "message": "Your message here"
}

Response:

{
  "response": "AI generated response"
}

JavaScript SDK - Super Simple

Just include our script and start using AI instantly - no backend code or API keys needed for basic usage!

Basic AI Chat

<html>
<body>
    <script src="https://apifreellm.com/apifree.min.js"></script>
    <script>
        // Chat with our free AI
        apifree.chat('What is the meaning of life?').then(apifree.print);
    </script>
</body>
</html>

Interactive Chat

<html>
<body>
    <input type="text" id="userInput" placeholder="Ask anything...">
    <button onclick="sendMessage()">Send</button>
    
    <script src="https://apifreellm.com/apifree.min.js"></script>
    <script>
        async function sendMessage() {
            const input = document.getElementById('userInput');
            const message = input.value;
            if (!message) return;
            
            input.value = 'Thinking...';
            try {
                const response = await apifree.chat(message);
                apifree.print(response);
                input.value = '';
            } catch (error) {
                console.error('Error:', error);
                input.value = 'Error occurred';
            }
        }
    </script>
</body>
</html>

Streaming Response

<html>
<body>
    <script src="https://apifreellm.com/apifree.min.js"></script>
    <script>
        // Stream response word by word
        apifree.streamChat(
            'Tell me a short story about AI',
            (chunk) => apifree.print(chunk)
        );
    </script>
</body>
</html>

Advanced Usage

<html>
<body>
    <script src="https://apifreellm.com/apifree.min.js"></script>
    <script>
        (async () => {
            // Multiple requests
            const questions = [
                'What is JavaScript?',
                'How does AI work?',
                'Tell me a fun fact'
            ];
            
            for (const question of questions) {
                console.log('Q:', question);
                const answer = await apifree.chat(question);
                console.log('A:', answer);
                console.log('---');
            }
        })();
    </script>
</body>
</html>

✨ No Setup Required: Just include the script and start using AI instantly. Perfect for prototypes, demos, and simple applications!

REST API Examples

For backend applications, use our REST API with any programming language:

cURL

curl -X POST https://apifreellm.com/api/chat \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "message": "Hello, how are you?",
    "model": "default"
  }'

JavaScript (Node.js/Browser)

const response = await fetch('https://apifreellm.com/api/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_API_KEY'
  },
  body: JSON.stringify({
    message: 'What is artificial intelligence?',
    model: 'default'
  })
});

const data = await response.json();
console.log(data.response);

Python

import requests

url = "https://apifreellm.com/api/chat"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
}
data = {
    "message": "Explain quantum computing",
    "model": "default"
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result["response"])

PHP

<?php
$url = 'https://apifreellm.com/api/chat';
$data = json_encode([
    'message' => 'What is the future of AI?',
    'model' => 'default'
]);

$context = stream_context_create([
    'http' => [
        'method' => 'POST',
        'header' => [
            'Content-Type: application/json',
            'Authorization: Bearer YOUR_API_KEY'
        ],
        'content' => $data
    ]
]);

$response = file_get_contents($url, false, $context);
$result = json_decode($response, true);
echo $result['response'];
?>

🔑 Need an API Key? Generate your free API key here for REST API access.

Authentication

Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Tip: Generate your free API key using the button above to see complete code examples.

Error Codes

200 - Success

Request completed successfully.

400 - Bad Request

Missing or invalid message parameter.

401 - Unauthorized

Invalid or missing API key.

500 - Server Error

Temporary server issue. Try again in a moment.