Developer Resources

API Documentation

Everything you need to integrate Lazyor.ai into your applications. Comprehensive guides, API references, and code examples.

50+ API Endpoints
10+ SDKs
100+ Code Examples

Quick Start

Get up and running with Lazyor.ai in minutes. This guide will walk you through making your first API request.

1. Get Your API Key

First, you'll need an API key. Sign up for a free account and generate your API key from the dashboard.

bash
export LAZYOR_API_KEY="your-api-key-here"

2. Make Your First Request

Here's a simple example using cURL to generate a chat completion:

bash
curl https://api.lazyor.ai/v1/chat/completions \
  -H "Authorization: Bearer $LAZYOR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {"role": "user", "content": "Hello, world!"}
    ]
  }'
Tip

You can also use our official SDKs for Python, Node.js, and Go for easier integration.

Authentication

All API requests must include an API key in the Authorization header using the Bearer token format.

http
Authorization: Bearer YOUR_API_KEY

Security Best Practices

  • Never expose your API key in client-side code
  • Use environment variables to store your API key
  • Rotate your API keys regularly
  • Use separate keys for different environments (dev/staging/prod)

Chat Completions

Generate text responses from AI models using the chat completions API.

Method /v1/chat/completions

Request Parameters

Parameter Type Required Description
model string Yes ID of the model to use (e.g., gpt-4, claude-3)
messages array Yes Array of message objects
temperature float No Sampling temperature (0-2, default: 1)
max_tokens integer No Maximum number of tokens to generate

Example Request

bash
curl https://api.lazyor.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of France?"}
    ],
    "temperature": 0.7,
    "max_tokens": 150
  }'
python
import requests

response = requests.post(
    "https://api.lazyor.ai/v1/chat/completions",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_API_KEY"
    },
    json={
        "model": "gpt-4",
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "What is the capital of France?"}
        ],
        "temperature": 0.7,
        "max_tokens": 150
    }
)

print(response.json())
javascript
const response = await fetch('https://api.lazyor.ai/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_API_KEY'
  },
  body: JSON.stringify({
    model: 'gpt-4',
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: 'What is the capital of France?' }
    ],
    temperature: 0.7,
    max_tokens: 150
  })
});

const data = await response.json();
console.log(data);
php
<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.lazyor.ai/v1/chat/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer YOUR_API_KEY'
]);

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'model' => 'gpt-4',
    'messages' => [
        ['role' => 'system', 'content' => 'You are a helpful assistant.'],
        ['role' => 'user', 'content' => 'What is the capital of France?']
    ],
    'temperature' => 0.7,
    'max_tokens' => 150
]));

$response = curl_exec($ch);
curl_close($ch);

echo $response;

Example Response

json
{
  "id": "chatcmpl-1234567890",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 8,
    "total_tokens": 33
  }
}

Streaming

To stream the response, set `stream: true` in your request. The API will return SSE (Server-Sent Events) data.

javascript
const response = await fetch('https://api.lazyor.ai/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_API_KEY'
  },
  body: JSON.stringify({
    model: 'gpt-4',
    messages: [{ role: 'user', content: 'Hello!' }],
    stream: true  // Enable streaming
  })
});

const reader = response.body.getReader();
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  // Process streaming data
}

Error Handling

Lazyor.ai uses standard HTTP response codes to indicate the success or failure of an API request.

Code Meaning Description
200 OK The request was successful
400 Bad Request The request was malformed or missing parameters
401 Unauthorized Invalid or missing API key
429 Too Many Requests Rate limit exceeded
500 Server Error Something went wrong on our end