Quick Start
Get started with Tokligence Gateway in 5 minutes.
Prerequisites
- Tokligence Gateway installed (Installation Guide)
- At least one LLM provider API key (OpenAI, Anthropic, or Google) OR a local LLM
Step 1: Start the Gateway
# Using the npm package
tgw start
# Or using the binary
./bin/gatewayd
# Default address: http://localhost:8081
Step 2: Configure a Provider
Using OpenAI
export TOKLIGENCE_OPENAI_API_KEY=sk-...
Using Anthropic
export TOKLIGENCE_ANTHROPIC_API_KEY=sk-ant-...
Using Local LLM (Ollama)
ollama serve
ollama run llama3
Step 3: Test the Gateway
Using the CLI
tgw chat "Hello, how are you?"
Using curl
curl -X POST http://localhost:8081/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer test" \
-d '{
"model": "gpt-4",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Using with Coding Agents
With OpenAI Codex CLI
Point Codex to the gateway:
# Configure Codex to use the gateway
export OPENAI_BASE_URL=http://localhost:8081/v1
export OPENAI_API_KEY=your-gateway-key
# Run Codex with Claude via the gateway
codex --full-auto --config 'model="claude-3-5-sonnet-20241022"'
With Claude Code
Point Claude Code to the gateway:
# Set the base URL in Claude Code settings
# API URL: http://localhost:8081/anthropic
# Configure gateway to translate to OpenAI
export TOKLIGENCE_OPENAI_API_KEY=sk-...
API Endpoints
OpenAI-Compatible
| Endpoint | Description |
|---|---|
POST /v1/chat/completions | Chat with tool calling support |
POST /v1/responses | Responses API with session management |
GET /v1/models | List available models |
POST /v1/embeddings | Text embeddings |
Anthropic Native
| Endpoint | Description |
|---|---|
POST /anthropic/v1/messages | Native Anthropic chat |
POST /anthropic/v1/messages/count_tokens | Token estimation |
Gemini Native
| Endpoint | Description |
|---|---|
POST /v1beta/models/{model}:generateContent | Gemini chat completion |
POST /v1beta/models/{model}:streamGenerateContent | Gemini streaming |
GET /v1beta/models | List Gemini models |
Model Routing
The gateway routes requests based on model name patterns:
# Configure via environment variable
export TOKLIGENCE_ROUTES="claude*=>anthropic,gpt-*=>openai,gemini-*=>google"
Examples:
model: "claude-3-haiku"→ Anthropic APImodel: "gpt-4"→ OpenAI APImodel: "gemini-pro"→ Google API
Work Modes
The gateway supports three operation modes:
| Mode | Behavior | Use Case |
|---|---|---|
auto (default) | Smart routing based on model and endpoint | Best for mixed workloads |
passthrough | Direct passthrough to upstream providers | Force native provider APIs |
translation | Only allows translation between formats | Force protocol conversion |
export TOKLIGENCE_WORK_MODE=auto # or passthrough, translation