Complete guide to integrating ZachAI. 100% OpenAI-compatible — drop-in replacement.
pip install openai or npm install openaibase_url to https://your-domain.com/api/v1 and use your ZachAI key.# Using the official OpenAI SDK (recommended)
from openai import OpenAI
client = OpenAI(
api_key="sk-zacht-...",
base_url="https://your-domain.com/api/v1",
)
# Non-streaming
response = client.chat.completions.create(
model="zachai-reason",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Write a Python function to check if a number is prime."},
],
)
print(response.choices[0].message.content)
print(f"Usage: {response.usage.total_tokens} tokens")// Using the official OpenAI SDK for Node.js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-zacht-...",
baseURL: "https://your-domain.com/api/v1",
});
const response = await client.chat.completions.create({
model: "zachai-reason",
messages: [
{ role: "user", content: "What is the capital of France?" },
],
});
console.log(response.choices[0].message.content);
console.log(`Usage: ${response.usage.total_tokens} tokens`);/v1/chat/completionsCreates a model response for the given chat conversation. Fully compatible with the OpenAI Chat Completions API.
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID: "zachai-flash", "zachai-reason", or "zachai-pro" |
messages | array | Yes | Array of message objects with role and content |
temperature | number | No | 0-2, default 0.7. Higher = more creative |
max_tokens | integer | No | Max output tokens (default 8192) |
stream | boolean | No | Enable SSE streaming (default false) |
top_p | number | No | Nucleus sampling, 0-1 (default 1) |
stop | string/array | No | Up to 4 stop sequences |
/v1/modelsReturns the list of available models with pricing, context length, and performance metrics.
/healthHealth check endpoint for monitoring. Returns service status, database connectivity, and deployment region.
ZachAI supports Server-Sent Events (SSE) streaming for real-time, token-by-token responses. Set stream: true in your request.
# Streaming with OpenAI SDK
from openai import OpenAI
client = OpenAI(
api_key="sk-zacht-...",
base_url="https://your-domain.com/api/v1",
)
stream = client.chat.completions.create(
model="zachai-flash",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)// Streaming in Node.js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-zacht-...",
baseURL: "https://your-domain.com/api/v1",
});
const stream = await client.chat.completions.create({
model: "zachai-flash",
messages: [{ role: "user", content: "Write a poem about the sea" }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}# Streaming response (SSE)
curl -X POST https://your-domain.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-zacht-..." \
-d '{
"model": "zachai-flash",
"messages": [
{ "role": "user", "content": "Write a haiku about coding" }
],
"stream": true
}'# Multi-turn conversation
from openai import OpenAI
client = OpenAI(api_key="sk-zacht-...", base_url="https://your-domain.com/api/v1")
messages = [{"role": "system", "content": "You are a coding tutor."}]
while True:
user_input = input("You: ")
if user_input.lower() in ["quit", "exit"]:
break
messages.append({"role": "user", "content": user_input})
response = client.chat.completions.create(
model="zachai-reason",
messages=messages,
)
reply = response.choices[0].message.content
print(f"AI: {reply}")
messages.append({"role": "assistant", "content": reply})// Using the OpenAI Go SDK
package main
import (
"context"
"fmt"
openai "github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig("sk-zacht-...")
config.BaseURL = "https://your-domain.com/api/v1"
client := openai.NewClientWithConfig(config)
resp, err := client.CreateChatCompletion(context.Background(),
openai.ChatCompletionRequest{
Model: "zachai-reason",
Messages: []openai.ChatCompletionMessage{
{Role: "user", Content: "Hello, what is 2+2?"},
},
},
)
if err != nil {
panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)
}ZachAI uses standard HTTP status codes. Here's how to handle common errors:
| Status Code | Error Type | Meaning |
|---|---|---|
200 | OK | Request successful |
400 | Bad Request | Invalid request body or parameters |
401 | Unauthorized | Missing or invalid API key |
402 | Payment Required | Insufficient balance |
429 | Rate Limit | Too many requests. Retry after delay |
500 | Server Error | Internal error. Retry with backoff |
503 | Service Unavailable | Upstream model temporarily unavailable |
# Error handling with retries
import openai
from openai import OpenAI
import time
client = OpenAI(api_key="sk-zacht-...", base_url="https://your-domain.com/api/v1")
def chat_with_retry(messages, max_retries=3):
for attempt in range(max_retries):
try:
response = client.chat.completions.create(
model="zachai-reason",
messages=messages,
)
return response.choices[0].message.content
except openai.RateLimitError:
wait = 2 ** attempt
print(f"Rate limited, waiting {wait}s...")
time.sleep(wait)
except openai.APIStatusError as e:
if e.status_code >= 500:
print(f"Server error {e.status_code}, retrying...")
time.sleep(2 ** attempt)
else:
raise
raise Exception("Max retries exceeded")| Model | Base Model | Context | TTFT | Input $/M | Output $/M |
|---|---|---|---|---|---|
| zachai-flash | DeepSeek V4 Flash | 128K | ~180ms | $0.08 | $0.18 |
| zachai-reason | GLM 5.3 | 128K | ~350ms | $0.30 | $0.65 |
| zachai-pro | Hunyuan 3 | 128K | ~600ms | $0.75 | $1.60 |
All prices in USD per million tokens. Powered by Tencent Cloud TokenHub.
X-RateLimit-Remaining, X-RateLimit-ResetRetry-After header tells you how long to wait.AP-Singapore. All inference runs on servers in Singapore.
Models powered by Tencent Cloud TokenHub. Commercial use included with all plans.
99.9% uptime SLA. Health check available at /health.
API keys stored as SHA-256 hashes. Usage logs retained for 30 days. No prompt content stored.