OpenAI-Compatible API Guide
Use existing OpenAI SDKs and tools with your Thox.ai device - complete setup and usage guide.
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
Get your API endpoint
Your Thox.ai API is available at:
http://thox.local:8080/v1Or use your device's IP address if mDNS is not available.
Configure your API key
Generate an API key from the web interface or CLI:
thox config get api.key
# Or generate a new one:
thox config set api.key $(openssl rand -hex 32)Make your first request
Test with curl:
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
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/chat/completions | Create a chat completion (recommended) |
| POST | /v1/completions | Create a text completion (legacy) |
| GET | /v1/models | List available models |
| POST | /v1/embeddings | Create text embeddings |
SDK Examples
Python (OpenAI SDK)
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
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
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:
# 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-keySupported Parameters
Request Parameters
modelmessagestemperaturemax_tokenstop_pstreamstoppresence_penaltyfrequency_penalty
Response Format
idobjectcreatedmodelchoicesusage.prompt_tokensusage.completion_tokensusage.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.