A powerful and lightweight API that provides seamless access to Claude 3.5 and Claude 3.7 models through multiple backends (Puter.com and DuckAI), featuring an OpenAI-compatible interface.
- Multiple Models: Support for both Claude 3.5 Sonnet and Claude 3.7 Sonnet
- Backend Flexibility: Automatic fallback between Puter.com and DuckAI backends
- OpenAI Compatibility: Drop-in replacement for OpenAI API calls
- Streaming Support: Real-time response streaming capability
- Zero Configuration: No API keys or complex setup required
- Lightweight: Built on Express.js for optimal performance
- Clone the repository:
git clone https://github.com/andresdevvv/free-sonnetapi.git
- Install dependencies:
cd free-sonnetapi
npm install
- Start the server:
node index.js
The server will start on port 3032 by default.
const response = await fetch('http://localhost:3032/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: "claude3.5", // or "claude3.7"
messages: [
{
"role": "user",
"content": "Write a hello world program in Python"
}
]
})
});
const data = await response.json();
const response = await fetch('http://localhost:3032/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: "claude3.7",
messages: [
{
"role": "system",
"content": "You are a helpful coding assistant"
},
{
"role": "user",
"content": "Write a hello world program in Python"
}
],
stream: true, // Enable streaming responses
source: "duckai" // Explicitly select backend source
})
});
{
"model": "claude-3-7-sonnet-latest",
"content": "Here's a simple Hello World program in Python:\n\nprint('Hello, World!')",
"usage": {
"prompt_tokens": 24,
"completion_tokens": 12,
"total_tokens": 36
}
}
- CORS Configuration: By default, CORS is disabled. Configure it appropriately in
routes/chat.js
based on your needs. - Rate Limiting: Consider implementing rate limiting for production use.
- Proxy Support: Use a reverse proxy (like Nginx) in production.
Option | Description | Default |
---|---|---|
PORT |
Server port | 3032 |
model |
AI model to use | claude3.5 |
source |
Backend source | puter |
stream |
Enable streaming | false |
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
For detailed documentation and API reference, visit: sonnetapi.andresdev.org
This project is licensed under the MIT License - see the LICENSE file for details.
While credit is not required, it is appreciated. Feel free to star the repository if you find it useful!