Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
433 changes: 433 additions & 0 deletions DEPLOYMENT.md

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions GIST_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# πŸ“¦ How to Create GitHub Gist for One-Line Deployment

## Step 1: Go to GitHub Gist

Visit: https://gist.github.com/

## Step 2: Create New Gist

Click "+" in top right β†’ "New gist"

## Step 3: Add Files

### File 1: README.md
- Filename: `README.md`
- Content: Copy from `GIST_README.md`

### File 2: deploy_qwen_api.sh
- Filename: `deploy_qwen_api.sh`
- Content: Copy from `deploy_qwen_api.sh`

## Step 4: Configure Gist

- Description: "πŸš€ Qwen API - One-Line Deployment Script | Complete OpenAI-compatible API deployment"
- Visibility: **Public**

## Step 5: Create Gist

Click "Create public gist"

## Step 6: Get Raw URL

After creation, click "Raw" button on `deploy_qwen_api.sh` to get URL like:
```
https://gist.githubusercontent.com/YOUR_USERNAME/GIST_ID/raw/deploy_qwen_api.sh
```

## Step 7: Test Deployment

```bash
export QWEN_EMAIL="your@email.com"
export QWEN_PASSWORD="yourpassword"
curl -sSL YOUR_RAW_URL | bash
```

## Step 8: Update Repository

Update main README.md with:

```markdown
## πŸš€ Quick Deployment

```bash
# Export credentials
export QWEN_EMAIL="your@email.com"
export QWEN_PASSWORD="yourpassword"

# Deploy with one command
curl -sSL https://gist.githubusercontent.com/YOUR_USERNAME/GIST_ID/raw/deploy_qwen_api.sh | bash
```
```

## βœ… Done!

Your one-line deployment is now live and shareable!

## πŸ“ Share Command

Share this with users:

```bash
# One-line deployment for Qwen API
export QWEN_EMAIL="your@email.com" QWEN_PASSWORD="yourpassword"
curl -sSL https://gist.githubusercontent.com/YOUR_USERNAME/GIST_ID/raw/deploy_qwen_api.sh | bash
```
244 changes: 244 additions & 0 deletions GIST_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
# πŸš€ Qwen API - One-Line Deployment Script

**Complete deployment of OpenAI-compatible Qwen API server in a single command!**

This script automatically handles:
- βœ… Environment setup
- βœ… Dependency installation
- βœ… Bearer token extraction (via Playwright)
- βœ… Server startup
- βœ… Health verification
- βœ… Test execution

## πŸ“‹ Prerequisites

- **Python 3.8+** (Python 3.10+ recommended)
- **Git** (for cloning the repository)
- **Qwen Account** (Get one at https://chat.qwen.ai)

## 🎯 One-Line Deployment

### Step 1: Export Credentials

```bash
export QWEN_EMAIL="your@email.com"
export QWEN_PASSWORD="yourpassword"
```

### Step 2: Deploy with cURL

```bash
curl -sSL https://raw.githubusercontent.com/Zeeeepa/qwen-api/main/deploy_qwen_api.sh | bash
```

Or with wget:

```bash
wget -qO- https://raw.githubusercontent.com/Zeeeepa/qwen-api/main/deploy_qwen_api.sh | bash
```

That's it! The script will:
1. πŸ” Validate prerequisites
2. πŸ“¦ Clone repository
3. 🐍 Setup Python environment
4. πŸ“š Install dependencies
5. 🎭 Install Playwright browsers
6. πŸ” Extract Bearer token
7. πŸš€ Start API server
8. βœ… Verify deployment

## 🌐 Using the API

### Python (OpenAI SDK)

```python
from openai import OpenAI

client = OpenAI(
api_key="sk-any", # βœ… Any key works!
base_url="http://localhost:8096/v1"
)

response = client.chat.completions.create(
model="gpt-4", # βœ… Any model works!
messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)
```

### cURL

```bash
curl -X POST http://localhost:8096/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-any" \
-d '{
"model": "gpt-4",
"messages": [{"role": "user", "content": "Hello!"}]
}'
```

### JavaScript/TypeScript

```javascript
import OpenAI from 'openai';

const client = new OpenAI({
apiKey: 'sk-any',
baseURL: 'http://localhost:8096/v1'
});

const response = await client.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
});

console.log(response.choices[0].message.content);
```

## πŸ“Š Available Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/` | GET | Root endpoint, service info |
| `/health` | GET | Health check |
| `/v1/models` | GET | List available models |
| `/v1/chat/completions` | POST | Chat completions (streaming & non-streaming) |
| `/docs` | GET | Interactive API documentation (Swagger UI) |

## 🎯 Model Mapping

**Any model name works!** The server intelligently maps model names:

| Your Request | Actual Model Used |
|--------------|-------------------|
| `gpt-4` | `qwen-turbo-latest` |
| `gpt-5` | `qwen-turbo-latest` |
| `claude-3` | `qwen-turbo-latest` |
| `qwen-turbo` | `qwen-turbo-latest` |
| `any-model-name` | `qwen-turbo-latest` |

## πŸ› οΈ Configuration

Set these environment variables before deployment:

```bash
# Required
export QWEN_EMAIL="your@email.com"
export QWEN_PASSWORD="yourpassword"

# Optional
export QWEN_API_PORT=8096 # Default: 8096
export QWEN_BEARER_TOKEN="..." # Skip Playwright extraction
```

## πŸ“ Useful Commands

```bash
# View logs
tail -f qwen-api/logs/server.log

# Stop server
kill $(cat qwen-api/server.pid)

# Check server status
curl http://localhost:8096/health

# Restart server
cd qwen-api && bash scripts/start.sh
```

## ✨ Features

- **πŸ” Automatic Playwright Authentication** - No manual token extraction needed
- **🎯 Any API Key Works** - Anonymous mode enabled by default
- **πŸ“¦ Any Model Name Works** - Smart defaulting to `qwen-turbo-latest`
- **🌊 Streaming Support** - Full SSE streaming for chat completions
- **πŸ“š OpenAI Compatible** - Drop-in replacement for OpenAI API
- **πŸ’Ύ Token Caching** - 12-hour session caching for performance

## πŸ› Troubleshooting

### Server won't start

```bash
# Check if port is in use
lsof -i :8096

# Kill process using port
kill $(lsof -t -i:8096)

# Try again
curl -sSL https://raw.githubusercontent.com/Zeeeepa/qwen-api/main/deploy_qwen_api.sh | bash
```

### Authentication fails

```bash
# Verify credentials
echo $QWEN_EMAIL
echo $QWEN_PASSWORD

# Try manual token extraction
cd qwen-api
source venv/bin/activate
python3 test_auth.py
```

### Python version issues

```bash
# Check Python version (need 3.8+)
python3 --version

# Install Python 3.10+ if needed
# Ubuntu/Debian:
sudo apt update && sudo apt install python3.10

# macOS:
brew install python@3.10
```

## πŸ“– Documentation

- **Full Documentation**: https://github.com/Zeeeepa/qwen-api
- **Issues**: https://github.com/Zeeeepa/qwen-api/issues
- **Pull Requests**: https://github.com/Zeeeepa/qwen-api/pulls

## πŸŽ‰ Success Output

After successful deployment, you should see:

```
╔════════════════════════════════════════════════════════════╗
β•‘ β•‘
β•‘ πŸŽ‰ Deployment Complete! πŸŽ‰ β•‘
β•‘ β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ“‘ Server Information:
βœ… Status: Running
🌐 URL: http://localhost:8096
πŸ“Š Health: http://localhost:8096/health
πŸ“š Docs: http://localhost:8096/docs
🎯 Models: http://localhost:8096/v1/models
πŸ”’ PID: 12345

βœ… All systems operational! Your Qwen API is ready to use.
```

## πŸ“„ License

MIT License - See repository for details

## πŸ‘€ Author

**Zeeeepa**
- GitHub: [@Zeeeepa](https://github.com/Zeeeepa)
- Repository: [qwen-api](https://github.com/Zeeeepa/qwen-api)

---

**Made with ❀️ for the AI community**

22 changes: 11 additions & 11 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Best for development and testing:
pip install -e .

# Run the server
python main.py
python start.py

# Or use the installed command
z-ai2api
Expand Down Expand Up @@ -78,7 +78,7 @@ For custom installations:
pip install -r requirements.txt

# Run directly
python main.py
python start.py
```

---
Expand Down Expand Up @@ -143,19 +143,19 @@ AUTH_TOKENS_FILE=tokens.txt

```bash
# Start with default settings (port 8080)
python main.py
python start.py

# Specify custom port
python main.py --port 8081
python start.py --port 8081

# Enable debug mode
python main.py --debug
python start.py --debug

# Specify host
python main.py --host 0.0.0.0 --port 8081
python start.py --host 0.0.0.0 --port 8081

# Show all options
python main.py --help
python start.py --help
```

### Using the Installed Command
Expand Down Expand Up @@ -298,7 +298,7 @@ FLAREPROX_AUTO_ROTATE=true

```bash
# Start server
python main.py --flareprox
python start.py --flareprox

# Check status
curl http://localhost:8080/stats
Expand All @@ -323,7 +323,7 @@ curl http://localhost:8080/stats
# Error: Port 8080 already in use

# Solution: Use different port
python main.py --port 8081
python start.py --port 8081
```

#### 2. Module Not Found
Expand Down Expand Up @@ -363,11 +363,11 @@ Enable detailed logging:

```bash
# CLI
python main.py --debug
python start.py --debug

# Environment variable
export DEBUG_LOGGING=true
python main.py
python start.py

# Check debug info
curl http://localhost:8080/debug
Expand Down
Loading