Skip to main content

Introduction

switchAILocal provides an OpenAI-compatible HTTP API that works with any OpenAI SDK or tool. Point your client to http://localhost:18080/v1 and use your existing code without modifications.

Base URL

http://localhost:18080/v1
All API endpoints use this base URL. The server runs locally on your machine by default.

Key Features

OpenAI Compatible

Works with OpenAI SDKs in Python, Node.js, and more without code changes

Multi-Provider

Access Gemini, Claude, Ollama, and other providers through a single endpoint

Auto-Routing

Omit provider prefixes to let switchAILocal choose the best available provider

Local-First

Everything runs on your machine - your data never leaves

Quick Example

curl http://localhost:18080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-test-123" \
  -d '{
    "model": "gemini-2.5-pro",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Available Endpoints

EndpointMethodDescription
/v1/chat/completionsPOSTSend chat messages and receive completions
/v1/completionsPOSTLegacy completions endpoint
/v1/modelsGETList all available models
/v1/providersGETList provider status and capabilities
/v1/embeddingsPOSTGenerate text embeddings
/v1/wsWebSocketReal-time bidirectional streaming
/v1/messagesPOSTClaude-compatible messages endpoint

Provider Support

switchAILocal supports multiple AI providers through a unified interface:

CLI Providers (Use Your Subscriptions)

  • Gemini CLI (geminicli:) - Google Gemini via local CLI
  • Claude CLI (claudecli:) - Anthropic Claude via local CLI
  • Codex (codex:) - OpenAI Codex
  • Vibe (vibe:) - Mistral Vibe CLI
  • OpenCode (opencode:) - OpenCode CLI

Local Models

  • Ollama (ollama:) - Local open-source models
  • LM Studio (lmstudio:) - Local model hosting

Cloud APIs

  • switchAI (switchai:) - Traylinx unified gateway
  • Gemini API (gemini:) - Google AI Studio
  • Claude API (claude:) - Anthropic API
  • OpenAI API (openai:) - OpenAI platform
  • OpenAI Compatible (openai-compat:) - OpenRouter, etc.

Error Handling

All errors follow the OpenAI error format:
{
  "error": {
    "message": "Invalid API key provided",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}

Common Error Types

TypeHTTP CodeDescription
authentication_error401Invalid or missing API key
invalid_request_error400Malformed request body
permission_error403Insufficient quota or permissions
rate_limit_error429Too many requests
server_error500Internal server error

Next Steps