OpenAI-Compatible API Guide

Use existing OpenAI SDKs and tools with your Thox.ai device - complete setup and usage guide.

Back to Articles

Thox.ai provides a fully OpenAI-compatible API, allowing you to use existing tools, SDKs, and applications without modification. Simply point your base_url to your Thox.ai device and start making requests.

Quick Start

1

Get your API endpoint

Your Thox.ai API is available at:

text
http://thox.local:8080/v1

Or use your device's IP address if mDNS is not available.

2

Configure your API key

Generate an API key from the web interface or CLI:

bash
thox config get api.key
# Or generate a new one:
thox config set api.key $(openssl rand -hex 32)
3

Make your first request

Test with curl:

bash
curl http://thox.local:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "thox-coder-14b",
    "messages": [
      {"role": "user", "content": "Write hello world in Python"}
    ]
  }'

Available Endpoints

MethodEndpointDescription
POST/v1/chat/completionsCreate a chat completion (recommended)
POST/v1/completionsCreate a text completion (legacy)
GET/v1/modelsList available models
POST/v1/embeddingsCreate text embeddings

SDK Examples

Python (OpenAI SDK)

python
from openai import OpenAI

client = OpenAI(
    base_url="http://thox.local:8080/v1",
    api_key="your-api-key"
)

response = client.chat.completions.create(
    model="thox-coder-14b",
    messages=[
        {"role": "system", "content": "You are a helpful coding assistant."},
        {"role": "user", "content": "Write a function to calculate fibonacci"}
    ],
    temperature=0.7,
    max_tokens=500
)

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

JavaScript/TypeScript

typescript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'http://thox.local:8080/v1',
  apiKey: 'your-api-key',
});

const response = await client.chat.completions.create({
  model: 'thox-coder-14b',
  messages: [
    { role: 'user', content: 'Explain async/await in JavaScript' }
  ],
  stream: true,
});

for await (const chunk of response) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

cURL with Streaming

bash
curl http://thox.local:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "thox-coder-14b",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }'

Environment Configuration

Set these environment variables to use Thox.ai as a drop-in replacement:

bash
# For OpenAI SDK compatibility
export OPENAI_API_BASE=http://thox.local:8080/v1
export OPENAI_API_KEY=your-api-key

# Or for explicit Thox configuration
export THOX_API_URL=http://thox.local:8080/v1
export THOX_API_KEY=your-api-key

Supported Parameters

Request Parameters

  • model
  • messages
  • temperature
  • max_tokens
  • top_p
  • stream
  • stop
  • presence_penalty
  • frequency_penalty

Response Format

  • id
  • object
  • created
  • model
  • choices
  • usage.prompt_tokens
  • usage.completion_tokens
  • usage.total_tokens

Tips & Best Practices

Use streaming for better UX

Enable "stream": true for real-time responses in interactive applications.

Local network only by default

The API is only accessible from your local network. Use SSH tunneling for remote access.

Model names differ

Use Thox model names (thox-coder-7b, thox-coder-14b, thox-coder-32b) instead of OpenAI model names.

Related Articles

Need API help?

Check our API documentation or contact support for integration assistance.