Introduction
PolyCopy is a Polymarket copy‑trading platform that lets users follow top traders, see a verifiable leaderboard, and experiment in a free paper‑mode. To keep the LLM‑driven recommendation engine lightweight and portable, many developers run it behind a simple proxy that can talk to several AI providers (OpenAI, Anthropic, Cohere, etc.). Docker gives you an isolated, reproducible environment for that proxy – one container, one command, and you’re ready for multi‑provider access.
Why Dockerize the LLM Proxy?
- Consistency – The same Python runtime, libraries, and environment variables run everywhere, from a local laptop to a CI server.
- Security – The container can be run with a non‑root user and limited network permissions, reducing the attack surface.
- Scalability – Spin up additional instances behind a load balancer without touching the host OS.
-
Simplicity – All configuration (API keys, provider selection, rate‑limit settings) lives in a single
docker‑compose.ymlor environment file.
Building the Container
Create a Dockerfile in the llm-proxy/ directory:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no‑cache‑dir -r requirements.txt
COPY . .
# Run as an unprivileged user for safety
RUN useradd -m appuser && chown -R appuser /app
USER appuser
EXPOSE 8000
CMD ["uvicorn", "proxy:app", "--host", "0.0.0.0", "--port", "8000"]
The requirements.txt should list FastAPI, Uvicorn, and any provider SDKs you need. The proxy module contains a tiny FastAPI app that forwards requests to the selected LLM service based on a header or query parameter.
Running the Proxy
# Build once
docker build -t polycopy-llm-proxy ./llm-proxy
# Run with environment variables for each provider
docker run -d \
-p 8000:8000 \
-e OPENAI_API_KEY=sk-... \
-e ANTHROPIC_API_KEY=sk-... \
-e COHERE_API_KEY=sk-... \
--name polycopy-llm-proxy \
polycopy-llm-proxy
You can also use docker‑compose.yml to keep the config in version control and start the whole stack with a single docker compose up -d.
Integrating with PolyCopy
PolyCopy’s backend talks to the proxy through a configurable URL (e.g., http://localhost:8000/v1/completions). Because the proxy normalises the request format, the rest of the code does not need to know which provider is answering. In paper‑mode the proxy can be pointed at a mock provider that returns deterministic responses, making tests reproducible.
FAQ
Q: Do I need a separate container for each LLM provider?
A: No. The proxy routes requests internally, so a single container can handle any number of providers as long as you supply the appropriate API keys.
Q: What happens if an API key expires?
A: The proxy will return a 401 error. PolyCopy catches this and falls back to another provider if one is configured.
Q: Can I limit the request rate per provider?
A: Yes. Implement a simple in‑memory rate limiter in the FastAPI middleware or use a side‑car like traefik with rate‑limit plugins.
Q: Is Docker required for production?
A: It is strongly recommended for reproducibility, but you can run the proxy directly with uvicorn if you manage dependencies manually.
Q: Where can I find more documentation?
A: The official repo includes a README.md with full setup instructions, and the live demo is at https://poly-copy.net.
Top comments (0)