This project is a simple proxy server for the Anthropic API, built using Go and the Fiber web framework. It allows you to route requests to the Anthropic API through your own server, which can be useful for adding custom logic, handling CORS issues, or masking the origin of requests.
- Proxies all requests to the Anthropic API
- Handles CORS (Cross-Origin Resource Sharing) headers
- Configurable port
- Timeout handling for long-running requests
- Go 1.16 or later
- Git
-
Clone the repository:
git clone https://github.com/yourusername/anthropic-api-proxy.git cd anthropic-api-proxy
-
Install dependencies:
go mod tidy
-
Set the
PORT
environment variable (optional, defaults to 3000):export PORT=8080
-
Run the server:
go run main.go
-
The server will start on the specified port (or 3000 if not specified). You can now send requests to
http://localhost:PORT/anthropic/*
, and they will be proxied to the Anthropic API.
PORT
: The port on which the server will listen. Defaults to 3000 if not set.DefaultTimeout
: The read and write timeout for the server. Currently set to 5 minutes.
The server proxies all requests to the Anthropic API. Simply replace the Anthropic API base URL with your proxy server's URL:
Original: https://api.anthropic.com/v1/complete
Proxied: http://localhost:PORT/anthropic/v1/complete
All request methods (GET, POST, PUT, DELETE, OPTIONS) are supported.
CORS is enabled for all origins (*
) by default. You can modify the CORS settings in the main.go
file if needed.
If there's an error proxying the request, the server will return an appropriate error response.
Contributions are welcome! Please feel free to submit a Pull Request.
This is an unofficial proxy for the Anthropic API and is not affiliated with or endorsed by Anthropic. Use at your own risk and ensure you comply with Anthropic's terms of service when using their API.