Skip to content

Instantly share code, notes, and snippets.

@AdamsGH
Created February 9, 2026 11:40
Show Gist options
  • Select an option

  • Save AdamsGH/12671124ac7ad64ed8089f3ce237feba to your computer and use it in GitHub Desktop.

Select an option

Save AdamsGH/12671124ac7ad64ed8089f3ce237feba to your computer and use it in GitHub Desktop.
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY proxy.py .
EXPOSE 8080
CMD ["python", "proxy.py"]
services:
anthropic-proxy:
build: .
ports:
- "8680:8080"
restart: unless-stopped
labels:
traefik.enable: "true"
traefik.http.routers.claude-proxy.rule: Host(`your.url.com`)
traefik.http.services.claude-proxy.loadbalancer.server.port: 8080
networks:
- "traefik"
networks:
traefik:
external: true
from flask import Flask, request, Response
import requests
app = Flask(__name__)
ANTHROPIC_BASE_URL = 'https://api.anthropic.com'
DEFAULT_API_VERSION = '2023-06-01'
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
def proxy(path):
url = f'{ANTHROPIC_BASE_URL}/{path}'
# Копируем все headers как есть (кроме host)
headers = {key: value for key, value in request.headers if key.lower() != 'host'}
# Добавляем anthropic-version если его нет
if 'anthropic-version' not in headers:
headers['anthropic-version'] = DEFAULT_API_VERSION
# Проксируем запрос
resp = requests.request(
method=request.method,
url=url,
headers=headers,
data=request.get_data(),
params=request.args,
stream=True,
timeout=90
)
# Фильтруем response headers - убираем те, что Flask управляет сам
response_headers = {
key: value for key, value in resp.headers.items()
if key.lower() not in ['transfer-encoding', 'content-encoding', 'content-length', 'connection']
}
# Возвращаем ответ
return Response(
resp.iter_content(chunk_size=1024),
status=resp.status_code,
headers=response_headers
)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
flask==3.0.0
requests==2.31.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment