Examples

Examples #

Practical examples to help you get started with LLMITE.

Basic Usage #

Simple Text Processing #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import requests

api_key = "sk-1234567890abcdef"
headers = {"Authorization": f"Bearer {api_key}"}

response = requests.post(
    "https://api.llmite.com/v1/models/text-processor/execute",
    headers=headers,
    json={
        "input": "Hello, world!",
        "parameters": {
            "temperature": 0.7
        }
    }
)

result = response.json()
print(result["output"])

Project Management #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# List all projects
response = requests.get(
    "https://api.llmite.com/v1/projects",
    headers=headers
)
projects = response.json()["projects"]

# Create a new project
new_project = requests.post(
    "https://api.llmite.com/v1/projects",
    headers=headers,
    json={
        "name": "My New Project",
        "description": "A sample project"
    }
)

JavaScript Examples #

Using Fetch API #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const apiKey = 'sk-1234567890abcdef';

async function processText(input) {
    const response = await fetch('https://api.llmite.com/v1/models/text-processor/execute', {
        method: 'POST',
        headers: {
            'Authorization': `Bearer ${apiKey}`,
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            input: input,
            parameters: {
                temperature: 0.7,
                max_tokens: 100
            }
        })
    });
    
    const result = await response.json();
    return result.output;
}

// Usage
processText("Translate this to French: Hello world")
    .then(output => console.log(output));

Node.js with Express #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const express = require('express');
const axios = require('axios');

const app = express();
const apiKey = process.env.LLMITE_API_KEY;

app.use(express.json());

app.post('/process', async (req, res) => {
    try {
        const response = await axios.post(
            'https://api.llmite.com/v1/models/text-processor/execute',
            {
                input: req.body.text,
                parameters: req.body.parameters || {}
            },
            {
                headers: {
                    'Authorization': `Bearer ${apiKey}`
                }
            }
        );
        
        res.json(response.data);
    } catch (error) {
        res.status(500).json({ error: error.message });
    }
});

app.listen(3000, () => {
    console.log('Server running on port 3000');
});

Curl Examples #

Basic Request #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
curl -X POST https://api.llmite.com/v1/models/text-processor/execute \
  -H "Authorization: Bearer sk-1234567890abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "Summarize this text: Lorem ipsum dolor sit amet...",
    "parameters": {
      "temperature": 0.5,
      "max_tokens": 50
    }
  }'

Batch Processing #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
curl -X POST https://api.llmite.com/v1/models/text-processor/batch \
  -H "Authorization: Bearer sk-1234567890abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [
      "First text to process",
      "Second text to process",
      "Third text to process"
    ],
    "parameters": {
      "temperature": 0.7
    }
  }'

Error Handling #

Python with Error Handling #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
from requests.exceptions import RequestException

def safe_api_call(endpoint, data):
    try:
        response = requests.post(
            f"https://api.llmite.com/v1/{endpoint}",
            headers={"Authorization": f"Bearer {api_key}"},
            json=data,
            timeout=30
        )
        response.raise_for_status()
        return response.json()
    
    except requests.exceptions.Timeout:
        print("Request timed out")
    except requests.exceptions.HTTPError as e:
        print(f"HTTP error: {e.response.status_code}")
        print(f"Error details: {e.response.json()}")
    except RequestException as e:
        print(f"Request failed: {e}")
    
    return None

Advanced Examples #

Streaming Responses #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import requests
import json

def stream_response(prompt):
    response = requests.post(
        "https://api.llmite.com/v1/models/text-processor/stream",
        headers={"Authorization": f"Bearer {api_key}"},
        json={"input": prompt, "stream": True},
        stream=True
    )
    
    for line in response.iter_lines():
        if line:
            data = json.loads(line.decode('utf-8'))
            if 'content' in data:
                print(data['content'], end='', flush=True)