API Reference

Complete API documentation for ExtendedLM endpoints

Overview

ExtendedLM provides a comprehensive REST API for chat, workflows, RAG, and more. All endpoints use JSON for request/response bodies and support authentication via API keys or session cookies.

Base URL

https://api.extendedlm.com

Authentication

# API Key (Header)
Authorization: Bearer YOUR_API_KEY

# Session Cookie (automatically set after login)
Cookie: session=...

Response Format

All responses follow this structure:

{
  "success": true,
  "data": { ... },
  "error": null,
  "timestamp": "2025-01-01T00:00:00Z"
}

// Error response
{
  "success": false,
  "data": null,
  "error": {
    "code": "INVALID_REQUEST",
    "message": "Missing required parameter: message"
  },
  "timestamp": "2025-01-01T00:00:00Z"
}

Rate Limiting

Rate limits are enforced per API key:

  • Free tier: 60 requests/minute
  • Pro tier: 300 requests/minute
  • Enterprise: Custom limits

Rate limit headers:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1640000000

Chat API

Create and manage AI conversations.

Create Conversation

POST /api/conversations
// Request
{
  "title": "My Conversation",
  "agent": "standard",
  "model": "gpt-4o",
  "systemPrompt": "You are a helpful assistant.",
  "metadata": {
    "tags": ["work", "code-review"]
  }
}

// Response
{
  "success": true,
  "data": {
    "id": "conv_abc123",
    "title": "My Conversation",
    "agent": "standard",
    "model": "gpt-4o",
    "created_at": "2025-01-01T00:00:00Z"
  }
}

Send Message

POST /api/chat
// Request
{
  "conversation_id": "conv_abc123",
  "message": "Explain quantum computing",
  "model": "gpt-4o",
  "temperature": 0.7,
  "max_tokens": 4096,
  "stream": true,
  "attachments": [
    {
      "type": "image",
      "url": "https://..."
    }
  ]
}

// Response (non-streaming)
{
  "success": true,
  "data": {
    "id": "msg_xyz789",
    "content": "Quantum computing is...",
    "role": "assistant",
    "model": "gpt-4o",
    "usage": {
      "prompt_tokens": 15,
      "completion_tokens": 150,
      "total_tokens": 165
    },
    "created_at": "2025-01-01T00:00:01Z"
  }
}

// Streaming response (Server-Sent Events)
event: token
data: {"token": "Quantum"}

event: token
data: {"token": " computing"}

event: done
data: {"message_id": "msg_xyz789", "usage": {...}}

List Conversations

GET /api/conversations
# Query parameters
?limit=20&offset=0&sort=created_at&order=desc&tags=work,code

# Response
{
  "success": true,
  "data": {
    "conversations": [...],
    "total": 42,
    "limit": 20,
    "offset": 0
  }
}

Get Conversation

GET /api/conversations/:id
{
  "success": true,
  "data": {
    "id": "conv_abc123",
    "title": "My Conversation",
    "messages": [
      {
        "id": "msg_001",
        "role": "user",
        "content": "Hello",
        "created_at": "2025-01-01T00:00:00Z"
      },
      {
        "id": "msg_002",
        "role": "assistant",
        "content": "Hi! How can I help?",
        "created_at": "2025-01-01T00:00:01Z"
      }
    ],
    "created_at": "2025-01-01T00:00:00Z",
    "updated_at": "2025-01-01T00:00:01Z"
  }
}

Delete Conversation

DELETE /api/conversations/:id

Workflow API

Create and execute visual workflows.

Create Workflow

POST /api/workflows
// Request
{
  "title": "Data Processing Pipeline",
  "description": "Process CSV data and generate report",
  "nodes": [
    {
      "id": "start",
      "type": "start",
      "position": { "x": 100, "y": 100 }
    },
    {
      "id": "llm1",
      "type": "llm",
      "data": {
        "model": "gpt-4o",
        "prompt": "Analyze this data: {input}",
        "temperature": 0.7
      },
      "position": { "x": 300, "y": 100 }
    },
    {
      "id": "end",
      "type": "end",
      "position": { "x": 500, "y": 100 }
    }
  ],
  "edges": [
    { "source": "start", "target": "llm1" },
    { "source": "llm1", "target": "end" }
  ]
}

// Response
{
  "success": true,
  "data": {
    "id": "wf_abc123",
    "title": "Data Processing Pipeline",
    "created_at": "2025-01-01T00:00:00Z"
  }
}

Execute Workflow

POST /api/workflows/:id/execute
// Request
{
  "input": "CSV data here...",
  "variables": {
    "threshold": 0.8,
    "format": "pdf"
  }
}

// Response (Server-Sent Events for streaming)
event: node_start
data: {"node_id": "llm1", "timestamp": "..."}

event: node_output
data: {"node_id": "llm1", "output": "Analysis: ..."}

event: node_complete
data: {"node_id": "llm1", "status": "success"}

event: workflow_complete
data: {"output": "Final result...", "duration_ms": 1234}

List Workflows

GET /api/workflows

Get Workflow

GET /api/workflows/:id

Update Workflow

PUT /api/workflows/:id

Delete Workflow

DELETE /api/workflows/:id

Get Execution History

GET /api/workflows/:id/executions

RAG API

Document upload, retrieval, and knowledge graph operations.

Upload Document

POST /api/rag/documents
# Multipart form data
curl -X POST https://api.extendedlm.com/api/rag/documents \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@document.pdf" \
  -F "title=Research Paper" \
  -F "metadata={\"category\":\"research\"}"

# Response
{
  "success": true,
  "data": {
    "id": "doc_abc123",
    "title": "Research Paper",
    "file_type": "pdf",
    "file_size": 1048576,
    "chunks_created": 42,
    "status": "processing"
  }
}

Query Documents

POST /api/rag/query
// Request
{
  "query": "What is the main conclusion?",
  "k": 5,
  "threshold": 0.7,
  "rerank": true,
  "use_graph": true,
  "filters": {
    "document_ids": ["doc_abc123"],
    "metadata": {
      "category": "research"
    }
  }
}

// Response
{
  "success": true,
  "data": {
    "chunks": [
      {
        "id": "chunk_001",
        "content": "The main conclusion is...",
        "similarity": 0.92,
        "document_id": "doc_abc123",
        "document_title": "Research Paper",
        "metadata": {
          "page": 5,
          "chunk_index": 12
        }
      }
    ],
    "entities": [
      {
        "name": "Neural Networks",
        "type": "CONCEPT",
        "relevance": 0.85
      }
    ]
  }
}

List Documents

GET /api/rag/documents

Get Document

GET /api/rag/documents/:id

Delete Document

DELETE /api/rag/documents/:id

Knowledge Graph Query

POST /api/rag/graph/query
// Request
{
  "query": "Find all entities related to 'Machine Learning'",
  "max_hops": 2,
  "entity_types": ["CONCEPT", "PERSON", "ORG"]
}

// Response
{
  "success": true,
  "data": {
    "entities": [
      {
        "id": "ent_001",
        "name": "Machine Learning",
        "type": "CONCEPT"
      },
      {
        "id": "ent_002",
        "name": "Deep Learning",
        "type": "CONCEPT"
      }
    ],
    "relationships": [
      {
        "source": "ent_001",
        "target": "ent_002",
        "type": "RELATED_TO"
      }
    ]
  }
}

Get Communities

GET /api/rag/graph/communities

MCP API

Manage Model Context Protocol servers and tools.

List MCP Servers

GET /api/mcp/servers
{
  "success": true,
  "data": {
    "servers": [
      {
        "id": "cal2prompt",
        "name": "Calendar Integration",
        "status": "running",
        "tools": 5,
        "enabled": true
      },
      {
        "id": "switchbot",
        "name": "SwitchBot",
        "status": "running",
        "tools": 8,
        "enabled": true
      }
    ]
  }
}

Get Server Tools

GET /api/mcp/servers/:id/tools
{
  "success": true,
  "data": {
    "tools": [
      {
        "name": "get_calendar_events",
        "description": "Get calendar events for a date range",
        "inputSchema": {
          "type": "object",
          "properties": {
            "start_date": { "type": "string" },
            "end_date": { "type": "string" }
          },
          "required": ["start_date", "end_date"]
        }
      }
    ]
  }
}

Call MCP Tool

POST /api/mcp/tools/call
// Request
{
  "server": "cal2prompt",
  "tool": "get_calendar_events",
  "arguments": {
    "start_date": "2025-01-01",
    "end_date": "2025-01-07"
  }
}

// Response
{
  "success": true,
  "data": {
    "result": [
      {
        "title": "Team Meeting",
        "start": "2025-01-03T10:00:00Z",
        "end": "2025-01-03T11:00:00Z"
      }
    ]
  }
}

Enable/Disable Server

PATCH /api/mcp/servers/:id
// Request
{
  "enabled": false
}

// Response
{
  "success": true,
  "data": {
    "id": "switchbot",
    "enabled": false
  }
}

Computer Use API

Mate endpoints for browser automation and command execution.

Execute Browser Action

POST /api/computer-use/browser
// Request
{
  "action": "navigate",
  "params": {
    "url": "https://example.com"
  }
}

// Other actions
{
  "action": "click",
  "params": {
    "selector": "#submit-button"
  }
}

{
  "action": "type",
  "params": {
    "selector": "input[name='search']",
    "text": "search query"
  }
}

{
  "action": "screenshot",
  "params": {
    "fullPage": true
  }
}

// Response
{
  "success": true,
  "data": {
    "screenshot": "data:image/png;base64,...",
    "url": "https://example.com"
  }
}

Execute Shell Command

POST /api/computer-use/shell
// Request
{
  "command": "ls -la",
  "cwd": "/workspace",
  "timeout": 30000
}

// Response
{
  "success": true,
  "data": {
    "stdout": "total 48\ndrwxr-xr-x ...",
    "stderr": "",
    "exitCode": 0
  }
}

File Operations

POST /api/computer-use/files
// Read file
{
  "operation": "read",
  "path": "/workspace/data.json"
}

// Write file
{
  "operation": "write",
  "path": "/workspace/output.txt",
  "content": "Hello, world!"
}

// List directory
{
  "operation": "list",
  "path": "/workspace"
}

// Response
{
  "success": true,
  "data": {
    "files": [
      {
        "name": "data.json",
        "size": 1024,
        "modified": "2025-01-01T00:00:00Z"
      }
    ]
  }
}

VNC Stream

GET /api/computer-use/vnc
<!-- Embed VNC viewer -->
<iframe
  src="/api/computer-use/vnc"
  width="1024"
  height="768"
></iframe>

Storage API

File upload and management via Supabase Storage.

Upload File

POST /api/storage/upload
curl -X POST https://api.extendedlm.com/api/storage/upload \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@image.png" \
  -F "bucket=uploads" \
  -F "path=images/image.png"

# Response
{
  "success": true,
  "data": {
    "path": "images/image.png",
    "url": "https://...supabase.co/storage/v1/object/public/uploads/images/image.png",
    "size": 102400
  }
}

List Files

GET /api/storage/files
# Query parameters
?bucket=uploads&path=images&limit=50

# Response
{
  "success": true,
  "data": {
    "files": [
      {
        "name": "image.png",
        "size": 102400,
        "created_at": "2025-01-01T00:00:00Z",
        "url": "https://..."
      }
    ]
  }
}

Delete File

DELETE /api/storage/files
// Request
{
  "bucket": "uploads",
  "paths": ["images/image.png"]
}

// Response
{
  "success": true,
  "data": {
    "deleted": 1
  }
}

Get Signed URL

POST /api/storage/signed-url
// Request
{
  "bucket": "uploads",
  "path": "images/image.png",
  "expiresIn": 3600
}

// Response
{
  "success": true,
  "data": {
    "signedUrl": "https://...?token=...",
    "expiresAt": "2025-01-01T01:00:00Z"
  }
}

Admin API

Administrative endpoints (requires admin role).

List Users

GET /api/admin/users
{
  "success": true,
  "data": {
    "users": [
      {
        "id": "user_001",
        "email": "user@example.com",
        "created_at": "2025-01-01T00:00:00Z",
        "usage": {
          "tokens_used": 1000000,
          "conversations": 42
        }
      }
    ],
    "total": 100
  }
}

Get User Usage

GET /api/admin/users/:id/usage
{
  "success": true,
  "data": {
    "user_id": "user_001",
    "period": "2025-01",
    "usage": {
      "total_tokens": 1000000,
      "input_tokens": 400000,
      "output_tokens": 600000,
      "api_calls": 500,
      "storage_bytes": 10485760,
      "cost_usd": 15.50
    },
    "breakdown": {
      "gpt-4o": 800000,
      "claude-sonnet-4": 200000
    }
  }
}

System Stats

GET /api/admin/stats
{
  "success": true,
  "data": {
    "users": {
      "total": 1000,
      "active_today": 250,
      "new_this_month": 50
    },
    "usage": {
      "total_tokens": 100000000,
      "total_api_calls": 50000,
      "storage_gb": 100
    },
    "performance": {
      "avg_response_time_ms": 850,
      "uptime_percent": 99.9,
      "error_rate_percent": 0.1
    }
  }
}

Update Feature Flags

PATCH /api/admin/users/:id/features
// Request
{
  "features": {
    "workflows": true,
    "computer_use": true,
    "max_tokens": 128000
  }
}

// Response
{
  "success": true,
  "data": {
    "user_id": "user_001",
    "features": {
      "workflows": true,
      "computer_use": true,
      "max_tokens": 128000
    }
  }
}

Gateway API

Gateway management and local LLM endpoints.

List Models

GET /Gateway/v1/models
{
  "object": "list",
  "data": [
    {
      "id": "llama-3.3-70b",
      "object": "model",
      "created": 1640000000,
      "owned_by": "meta"
    },
    {
      "id": "qwen2.5-72b",
      "object": "model",
      "created": 1640000000,
      "owned_by": "alibaba"
    }
  ]
}

Load Model

POST /Gateway/v1/models/load
// Request
{
  "model": "llama-3.3-70b",
  "n_gpu_layers": 35,
  "n_ctx": 131072
}

// Response
{
  "success": true,
  "model": "llama-3.3-70b",
  "status": "loaded"
}

Unload Model

POST /Gateway/v1/models/unload

Chat Completion (OpenAI-compatible)

POST /Gateway/v1/chat/completions
// Request (same as OpenAI API)
{
  "model": "llama-3.3-70b",
  "messages": [
    {
      "role": "user",
      "content": "Hello!"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 1024,
  "stream": false
}

// Response (OpenAI-compatible)
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1640000000,
  "model": "llama-3.3-70b",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 10,
    "total_tokens": 15
  }
}

Gateway Stats

GET /Gateway/stats
{
  "loaded_model": "llama-3.3-70b",
  "memory_used_mb": 45000,
  "memory_total_mb": 81920,
  "gpu_layers": 35,
  "context_size": 131072,
  "requests_processed": 1000,
  "avg_tokens_per_second": 45
}

Webhooks

Configure webhooks to receive real-time notifications.

Create Webhook

POST /api/webhooks
// Request
{
  "url": "https://yourapp.com/webhook",
  "events": ["conversation.created", "message.created", "workflow.completed"],
  "secret": "your-webhook-secret"
}

// Response
{
  "success": true,
  "data": {
    "id": "wh_abc123",
    "url": "https://yourapp.com/webhook",
    "events": ["conversation.created", "message.created"],
    "created_at": "2025-01-01T00:00:00Z"
  }
}

Webhook Events

  • conversation.created - New conversation created
  • message.created - New message in conversation
  • workflow.started - Workflow execution started
  • workflow.completed - Workflow execution completed
  • document.uploaded - Document uploaded to RAG
  • document.processed - Document processing completed

Webhook Payload

{
  "event": "message.created",
  "timestamp": "2025-01-01T00:00:00Z",
  "data": {
    "id": "msg_xyz789",
    "conversation_id": "conv_abc123",
    "role": "assistant",
    "content": "Hello!",
    "created_at": "2025-01-01T00:00:00Z"
  }
}

Webhook Signature Verification

// Verify webhook signature
import crypto from 'crypto';

function verifyWebhook(payload: string, signature: string, secret: string) {
  const hmac = crypto.createHmac('sha256', secret);
  hmac.update(payload);
  const expectedSignature = hmac.digest('hex');

  return signature === expectedSignature;
}

// Express middleware
app.post('/webhook', (req, res) => {
  const signature = req.headers['x-webhook-signature'];
  const payload = JSON.stringify(req.body);

  if (!verifyWebhook(payload, signature, WEBHOOK_SECRET)) {
    return res.status(401).json({ error: 'Invalid signature' });
  }

  // Process webhook...
});

Error Codes

Standard error codes returned by the API.

Code HTTP Status Description
INVALID_REQUEST 400 Request validation failed (missing/invalid parameters)
UNAUTHORIZED 401 Missing or invalid authentication
FORBIDDEN 403 Insufficient permissions
NOT_FOUND 404 Resource not found
RATE_LIMIT_EXCEEDED 429 Too many requests
INTERNAL_ERROR 500 Server error
SERVICE_UNAVAILABLE 503 Service temporarily unavailable
MODEL_ERROR 500 LLM provider error
QUOTA_EXCEEDED 429 Usage quota exceeded

SDK Examples

Example code for using the API in different languages.

JavaScript/TypeScript

import { ExtendedLMClient } from '@extendedlm/sdk';

const client = new ExtendedLMClient({
  apiKey: process.env.EXTENDEDLM_API_KEY,
  baseURL: 'https://api.extendedlm.com',
});

// Create conversation
const conversation = await client.conversations.create({
  title: 'My Conversation',
  agent: 'standard',
  model: 'gpt-4o',
});

// Send message
const message = await client.chat.send({
  conversationId: conversation.id,
  message: 'Hello!',
  stream: true,
  onToken: (token) => console.log(token),
  onComplete: (msg) => console.log('Done:', msg),
});

Python

from extendedlm import ExtendedLM

client = ExtendedLM(api_key=os.environ['EXTENDEDLM_API_KEY'])

# Create conversation
conversation = client.conversations.create(
    title='My Conversation',
    agent='standard',
    model='gpt-4o'
)

# Send message with streaming
for token in client.chat.stream(
    conversation_id=conversation.id,
    message='Hello!'
):
    print(token, end='', flush=True)

cURL

# Create conversation
curl -X POST https://api.extendedlm.com/api/conversations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My Conversation",
    "agent": "standard",
    "model": "gpt-4o"
  }'

# Send message
curl -X POST https://api.extendedlm.com/api/chat \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "conversation_id": "conv_abc123",
    "message": "Hello!",
    "stream": false
  }'