Documentation

Everything you need to integrate Tokligence into your applications. Our API is fully compatible with the OpenAI format.

Quick Start

Get started with Tokligence in just a few steps:

  1. Create an account and get your API key from the Dashboard
  2. Set your API base URL to http://localhost:8081/v1
  3. Use your API key in the Authorization: Bearer header
  4. Start making requests using OpenAI-compatible format

Code Examples

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(
    api_key="tk-xxxxxxxxxxxx",  # Your Tokligence API key
    base_url="http://localhost:8081/v1"
)

response = client.chat.completions.create(
    model="claude-3-5-sonnet",  # Check /models for available models
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.choices[0].message.content)

cURL

curl http://localhost:8081/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer tk-xxxxxxxxxxxx" \
  -d '{
    "model": "claude-3-5-sonnet",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

JavaScript / TypeScript

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'tk-xxxxxxxxxxxx',  // Your Tokligence API key
  baseURL: 'http://localhost:8081/v1'
});

const response = await client.chat.completions.create({
  model: 'claude-3-5-sonnet',  // Check /models for available models
  messages: [
    { role: 'user', content: 'Hello!' }
  ]
});

console.log(response.choices[0].message.content);

Streaming (Python)

from openai import OpenAI

client = OpenAI(
    api_key="tk-xxxxxxxxxxxx",
    base_url="http://localhost:8081/v1"
)

stream = client.chat.completions.create(
    model="claude-3-5-sonnet",
    messages=[{"role": "user", "content": "Write a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

API Reference

Chat Completions

Create chat completions with any supported model. Supports both streaming and non-streaming modes.

POST /v1/chat/completions

List Models

Retrieve a list of all available models with pricing info.

GET /v1/models

List Providers

Get information about available LLM providers.

GET /v1/providers

Embeddings

Optional

Create embeddings for text inputs (if enabled).

POST /v1/embeddings

Image Generation

Optional

Generate images using DALL-E or other providers (if enabled).

POST /v1/images/generations

Rerank

Optional

Rerank documents based on relevance (if enabled).

POST /v1/rerank

Endpoints marked as "Optional" may not be available depending on your deployment configuration. Contact your administrator for details.

Authentication

All API requests require authentication using an API key. Include your API key in the Authorization header:

Authorization: Bearer tk-xxxxxxxxxxxx

API keys start with tk- prefix.

You can create and manage your API keys in the Dashboard → API Keys.

For organizations, API keys can be managed at Organization → API Keys.

Supported Models

Available models are dynamically configured by administrators. Common providers include:

Anthropic

Claude family models including Sonnet, Opus, and Haiku variants

OpenAI

GPT-4, GPT-4o, GPT-3.5 Turbo and other OpenAI models

Google

Gemini family models with multimodal capabilities

DeepSeek

Cost-effective models for chat and coding tasks

Azure OpenAI

Enterprise-grade OpenAI models via Azure

More Providers

Additional providers can be configured by administrators

View the complete list of currently available models and pricing on the Models page.

Rate Limits

Rate limits are configured per API key and may vary based on your plan. The following headers are included in API responses:

X-RateLimit-Limit: 60          # Max requests per window
X-RateLimit-Remaining: 58      # Requests remaining
X-RateLimit-Reset: 1699999999  # Window reset timestamp

If you exceed your rate limit, the API returns 429 Too Many Requests. Wait until the reset time or contact your administrator for limit increases.

Error Handling

The API returns standard HTTP status codes and JSON error responses:

400

Bad Request

Invalid request parameters or model not allowed

401

Unauthorized

Missing or invalid API key

402

Insufficient Balance

Account balance is too low for this request

429

Too Many Requests

Rate limit exceeded

503

Service Unavailable

Upstream provider error or server shutting down

Ready to Get Started?

Create a free account and start building with our API today.