Docker Integration
Containerize AI-powered applications with Antbase. Pass your API key as an environment variable and use any OpenAI-compatible SDK inside your container.
What this enables
- Reproducible AI app deployments with Docker
- Environment-based configuration for different stages
- Multi-service setups with Docker Compose
- Easy deployment to any container platform (K8s, ECS, Fly.io)
Quick Start
1. Create a Python AI app
# app.py
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["ANTBASE_API_KEY"],
base_url="https://antbase.ai/v1",
)
response = client.chat.completions.create(
model="ant:auto",
messages=[{"role": "user", "content": "Hello from Docker!"}],
)
print(response.choices[0].message.content)2. Create a Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "app.py"]# requirements.txt
openai>=1.03. Build and run
docker build -t my-ai-app .
docker run -e ANTBASE_API_KEY=your-ant-api-key my-ai-appConfiguration
Docker Compose
# docker-compose.yml
version: '3.8'
services:
ai-api:
build: .
ports:
- "8080:8080"
environment:
- ANTBASE_API_KEY=${ANTBASE_API_KEY}
- ANTBASE_BASE_URL=https://antbase.ai/v1
- ANTBASE_MODEL=ant:auto
restart: unless-stoppedUsing .env file
# .env (do NOT commit this file)
ANTBASE_API_KEY=your-ant-api-keydocker compose --env-file .env upUsage Examples
Node.js API server
FROM node:20-slim
WORKDIR /app
COPY package*.json .
RUN npm ci --production
COPY . .
EXPOSE 8080
CMD ["node", "server.js"]// server.js
import express from 'express';
import OpenAI from 'openai';
const app = express();
app.use(express.json());
const openai = new OpenAI({
apiKey: process.env.ANTBASE_API_KEY,
baseURL: 'https://antbase.ai/v1',
});
app.post('/chat', async (req, res) => {
const { message } = req.body;
const response = await openai.chat.completions.create({
model: 'ant:auto',
messages: [{ role: 'user', content: message }],
});
res.json({ reply: response.choices[0].message.content });
});
app.listen(8080, () => console.log('Server running on :8080'));Multi-stage build
# Build stage
FROM node:20-slim AS builder
WORKDIR /app
COPY package*.json .
RUN npm ci
COPY . .
RUN npm run build
# Production stage
FROM node:20-slim
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 8080
CMD ["node", "dist/server.js"]Virtual Models
| Model | Best for | Notes |
|---|---|---|
| ant:auto | General use | Recommended default |
| ant:fast | High-throughput APIs | Low latency for API endpoints |
| ant:best | Complex tasks | Frontier models for quality output |
| ant:free | Dev/staging | Zero cost for non-production |
| ant:reasoning | Analysis | Chain-of-thought reasoning |
| ant:coder | Code tasks | Code-optimized models |
See Virtual Models for the full list.
Troubleshooting
API key not found in container
Never hardcode API keys in your Dockerfile or image. Pass them at runtime with -e ANTBASE_API_KEY=... or use Docker secrets / a secret manager in production.
DNS resolution issues
If you get connection errors from inside the container, ensure DNS is working: docker run --dns 8.8.8.8 .... Some corporate networks block container DNS.