Spaces:
Running
Running
Deploy LiteLLM proxy
Browse files- Dockerfile +17 -0
- README.md +44 -5
- config.yaml +36 -0
Dockerfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 4 |
+
PYTHONUNBUFFERED=1 \
|
| 5 |
+
PORT=7860 \
|
| 6 |
+
HOST=0.0.0.0
|
| 7 |
+
|
| 8 |
+
WORKDIR /app
|
| 9 |
+
|
| 10 |
+
# LiteLLM proxy (OpenAI-compatible gateway)
|
| 11 |
+
RUN pip install --no-cache-dir "litellm[proxy]"
|
| 12 |
+
|
| 13 |
+
COPY config.yaml /app/config.yaml
|
| 14 |
+
|
| 15 |
+
EXPOSE 7860
|
| 16 |
+
|
| 17 |
+
CMD ["litellm", "--config", "/app/config.yaml"]
|
README.md
CHANGED
|
@@ -1,10 +1,49 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji: 🚀
|
| 4 |
-
colorFrom: purple
|
| 5 |
-
colorTo: gray
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: LiteLLM Proxy
|
|
|
|
|
|
|
|
|
|
| 3 |
sdk: docker
|
| 4 |
+
app_port: 7860
|
| 5 |
pinned: false
|
| 6 |
---
|
| 7 |
|
| 8 |
+
# LiteLLM Proxy (OpenAI-Compatible)
|
| 9 |
+
|
| 10 |
+
This Space runs the LiteLLM proxy, providing an OpenAI-compatible API that can route to multiple providers.
|
| 11 |
+
|
| 12 |
+
## Secrets to Set (Space Settings -> Secrets)
|
| 13 |
+
|
| 14 |
+
- `LITELLM_MASTER_KEY`: master key required in `Authorization: Bearer ...`
|
| 15 |
+
- `OPENAI_API_KEY`: for OpenAI routing
|
| 16 |
+
- `ANTHROPIC_API_KEY`: for Anthropic routing
|
| 17 |
+
|
| 18 |
+
## Useful Endpoints
|
| 19 |
+
|
| 20 |
+
- `GET /health/liveliness` (no auth) - good for keep-alive pings
|
| 21 |
+
- `POST /chat/completions` (auth) - OpenAI-compatible chat completions
|
| 22 |
+
|
| 23 |
+
## Example Curl
|
| 24 |
+
|
| 25 |
+
```bash
|
| 26 |
+
curl -sS https://YOUR-SPACE.hf.space/health/liveliness
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
curl -sS https://YOUR-SPACE.hf.space/chat/completions \
|
| 31 |
+
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
|
| 32 |
+
-H "Content-Type: application/json" \
|
| 33 |
+
-d '{
|
| 34 |
+
"model": "gpt-4o-mini",
|
| 35 |
+
"messages": [{"role": "user", "content": "Say hi"}]
|
| 36 |
+
}'
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Anthropic via alias:
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
curl -sS https://YOUR-SPACE.hf.space/chat/completions \
|
| 43 |
+
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
|
| 44 |
+
-H "Content-Type: application/json" \
|
| 45 |
+
-d '{
|
| 46 |
+
"model": "claude-sonnet",
|
| 47 |
+
"messages": [{"role": "user", "content": "Say hi from Claude"}]
|
| 48 |
+
}'
|
| 49 |
+
```
|
config.yaml
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_list:
|
| 2 |
+
# Friendly aliases (recommended)
|
| 3 |
+
- model_name: gpt-4o-mini
|
| 4 |
+
litellm_params:
|
| 5 |
+
model: openai/gpt-4o-mini
|
| 6 |
+
api_key: "os.environ/OPENAI_API_KEY"
|
| 7 |
+
|
| 8 |
+
# Pick a modern, fast Claude Sonnet variant as the default alias.
|
| 9 |
+
# You can still call any Anthropic model via `anthropic/<model>` because of the wildcard route.
|
| 10 |
+
- model_name: claude-sonnet
|
| 11 |
+
litellm_params:
|
| 12 |
+
model: anthropic/claude-3-7-sonnet-20250219
|
| 13 |
+
api_key: "os.environ/ANTHROPIC_API_KEY"
|
| 14 |
+
|
| 15 |
+
# Optional: allow explicit provider-prefixed model names
|
| 16 |
+
- model_name: openai/*
|
| 17 |
+
litellm_params:
|
| 18 |
+
model: openai/*
|
| 19 |
+
api_key: "os.environ/OPENAI_API_KEY"
|
| 20 |
+
model_info:
|
| 21 |
+
health_check_model: openai/gpt-4o-mini
|
| 22 |
+
|
| 23 |
+
- model_name: anthropic/*
|
| 24 |
+
litellm_params:
|
| 25 |
+
model: anthropic/*
|
| 26 |
+
api_key: "os.environ/ANTHROPIC_API_KEY"
|
| 27 |
+
model_info:
|
| 28 |
+
health_check_model: anthropic/claude-3-7-sonnet-20250219
|
| 29 |
+
|
| 30 |
+
litellm_settings:
|
| 31 |
+
# Improves compatibility when clients send provider-specific params.
|
| 32 |
+
drop_params: true
|
| 33 |
+
|
| 34 |
+
general_settings:
|
| 35 |
+
# Require Authorization: Bearer <key>.
|
| 36 |
+
master_key: "os.environ/LITELLM_MASTER_KEY"
|