{"id":29987125,"url":"https://github.com/privapps/github-copilot-svcs","last_synced_at":"2025-08-04T22:12:31.464Z","repository":{"id":308116368,"uuid":"1031663650","full_name":"privapps/github-copilot-svcs","owner":"privapps","description":"Github Copilot As a Service","archived":false,"fork":false,"pushed_at":"2025-08-04T09:14:36.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-04T09:45:31.896Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/privapps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-04T06:35:10.000Z","updated_at":"2025-08-04T07:01:16.000Z","dependencies_parsed_at":"2025-08-04T09:58:47.949Z","dependency_job_id":null,"html_url":"https://github.com/privapps/github-copilot-svcs","commit_stats":null,"previous_names":["privapps/github-copilot-svcs"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/privapps/github-copilot-svcs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privapps%2Fgithub-copilot-svcs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privapps%2Fgithub-copilot-svcs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privapps%2Fgithub-copilot-svcs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privapps%2Fgithub-copilot-svcs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/privapps","download_url":"https://codeload.github.com/privapps/github-copilot-svcs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privapps%2Fgithub-copilot-svcs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268789250,"owners_count":24307800,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-04T22:12:30.318Z","updated_at":"2025-08-04T22:12:31.420Z","avatar_url":"https://github.com/privapps.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GitHub Copilot SVCS Proxy\n\nThis project provides a reverse proxy for GitHub Copilot, exposing OpenAI-compatible endpoints for use with tools and clients that expect the OpenAI API. It follows the authentication and token management approach used by [OpenCode](https://github.com/sst/opencode).\n\n## Features\n\n- **OAuth Device Flow Authentication**: Secure authentication with GitHub Copilot using the same flow as OpenCode\n- **Advanced Token Management**: \n  - Proactive token refresh (refreshes at 20% of token lifetime, minimum 5 minutes)\n  - Exponential backoff retry logic for failed token refreshes\n  - Automatic fallback to full re-authentication when needed\n  - Detailed token status monitoring\n- **Robust Request Handling**:\n  - Automatic retry with exponential backoff for chat completions (3 attempts)\n  - Network error recovery and rate limiting handling\n  - 30-second request timeout protection\n- **OpenAI-Compatible API**: Exposes `/v1/chat/completions` and `/v1/models` endpoints\n- **Request/Response Transformation**: Handles model name mapping and ensures OpenAI compatibility\n- **Configurable Port**: Default port 8081, configurable via CLI or config file\n- **Health Monitoring**: `/health` endpoint for service monitoring\n- **Graceful Shutdown**: Proper signal handling and graceful server shutdown\n- **Comprehensive Logging**: Request/response logging for debugging and monitoring\n- **Enhanced CLI Commands**: Status monitoring, manual token refresh, and detailed configuration display\n\n## Downloads\n\nPre-built binaries are available for each release on the [Releases page](https://github.com/privapps/github-copilot-svcs/releases).\n\nAvailable platforms:\n- **Linux**: AMD64, ARM64\n- **macOS**: AMD64 (Intel), ARM64 (Apple Silicon) \n- **Windows**: AMD64, ARM64\n\n### Automated Releases\n\nReleases are automatically created when code is merged to the `main` branch:\n- Version numbers follow semantic versioning (starting from v0.0.1)\n- Cross-platform binaries are built and attached to each release\n- Release notes include download links for all supported platforms\n\n## Quickstart with Makefile\n\nIf you have `make` installed, you can build, run, and test the project easily:\n\n```bash\nmake build      # Build the binary\nmake run        # Start the proxy server\nmake auth       # Authenticate with GitHub Copilot\nmake models     # List available models\nmake config     # Show current configuration\nmake clean      # Remove the binary\n```\n\n## Installation \u0026 Usage\n\n### 1. Build the Application\n```bash\nmake build\n# or manually:\ngo build -o github-copilot-svcs\n```\n\n### 2. First Time Setup \u0026 Authentication\n```bash\nmake auth\n# or manually:\n./github-copilot-svcs auth\n```\n\n### 3. Start the Proxy Server\n```bash\nmake run\n# or manually:\n./github-copilot-svcs run\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `run`    | Start the proxy server |\n| `auth`   | Authenticate with GitHub Copilot using device flow |\n| `status` | Show detailed authentication and token status |\n| `config` | Display current configuration details |\n| `models` | List all available AI models |\n| `refresh`| Manually force token refresh |\n| `version`| Show version information |\n| `help`   | Show usage information |\n\n### Enhanced Status Monitoring\n\nThe `status` command now provides detailed token information:\n\n```bash\n./github-copilot-svcs status\n```\n\nExample output:\n```\nConfiguration file: ~/.local/share/github-copilot-svcs/config.json\nPort: 8081\nAuthentication: ✓ Authenticated\nToken expires: in 29m 53s (1793 seconds)\nStatus: ✅ Token is healthy\nHas GitHub token: true\nRefresh interval: 1500 seconds\n```\n\nStatus indicators:\n- ✅ **Token is healthy**: Token has plenty of time remaining\n- ⚠️ **Token will be refreshed soon**: Token is approaching refresh threshold\n- ❌ **Token needs refresh**: Token has expired or will expire very soon\n\n## API Endpoints\n\nOnce running, the proxy exposes these OpenAI-compatible endpoints:\n\n### Chat Completions\n```bash\nPOST http://localhost:8081/v1/chat/completions\nContent-Type: application/json\n\n{\n  \"model\": \"gpt-4\",\n  \"messages\": [\n    {\"role\": \"user\", \"content\": \"Hello, world!\"}\n  ],\n  \"max_tokens\": 100\n}\n```\n\n### Available Models\n```bash\nGET http://localhost:8081/v1/models\n```\n\n### Health Check\n```bash\nGET http://localhost:8081/health\n```\n\n## Reliability \u0026 Error Handling\n\n### Automatic Token Management\n\nThe proxy implements proactive token management to minimize authentication interruptions:\n\n- **Proactive Refresh**: Tokens are refreshed when 20% of their lifetime remains (typically 5-6 minutes before expiration for 25-minute tokens)\n- **Retry Logic**: Failed token refreshes are retried up to 3 times with exponential backoff (2s, 8s, 18s delays)\n- **Fallback Authentication**: If token refresh fails completely, the system falls back to full device flow re-authentication\n- **Background Monitoring**: Token status is continuously monitored during API requests\n\n### Request Retry Logic\n\nChat completion requests are automatically retried to handle transient failures:\n\n- **Automatic Retries**: Up to 3 attempts for failed requests\n- **Smart Retry Logic**: Only retries on network errors, server errors (5xx), rate limiting (429), and timeouts (408)\n- **Exponential Backoff**: Retry delays of 1s, 4s, 9s to avoid overwhelming the API\n- **Timeout Protection**: 30-second timeout per request attempt\n\n### Error Recovery\n\n```bash\n# Manual token refresh if needed\n./github-copilot-svcs refresh\n\n# Check current token status\n./github-copilot-svcs status\n\n# Re-authenticate if all else fails\n./github-copilot-svcs auth\n```\n\n## Configuration\n\nThe configuration is stored in `~/.local/share/github-copilot-svcs/config.json`:\n\n```json\n{\n  \"port\": 8081,\n  \"github_token\": \"gho_...\",\n  \"copilot_token\": \"ghu_...\",\n  \"expires_at\": 1720000000,\n  \"refresh_in\": 1500\n}\n```\n\n### Configuration Fields\n\n- `port`: Server port (default: 8081)\n- `github_token`: GitHub OAuth token for Copilot access\n- `copilot_token`: GitHub Copilot API token\n- `expires_at`: Unix timestamp when the Copilot token expires\n- `refresh_in`: Seconds until token should be refreshed (typically 1500 = 25 minutes)\n\n## Authentication Flow\n\nThe authentication follows GitHub Copilot's OAuth device flow:\n\n1. **Device Authorization**: Generates a device code and user code\n2. **User Authorization**: User visits GitHub and enters the user code\n3. **Token Exchange**: Polls for GitHub OAuth token\n4. **Copilot Token**: Exchanges GitHub token for Copilot API token\n5. **Automatic Refresh**: Refreshes Copilot token as needed\n\n## Model Mapping\n\nThe proxy automatically maps common model names to GitHub Copilot models:\n\n| Input Model | GitHub Copilot Model | Provider |\n|-------------|---------------------|----------|\n| `gpt-4o`, `gpt-4.1` | As specified | OpenAI |\n| `o3`, `o3-mini`, `o4-mini` | As specified | OpenAI |\n| `claude-3.5-sonnet`, `claude-3.7-sonnet`, `claude-3.7-sonnet-thought` | As specified | Anthropic |\n| `claude-opus-4`, `claude-sonnet-4` | As specified | Anthropic |\n| `gemini-2.5-pro`, `gemini-2.0-flash-001` | As specified | Google |\n\n**Supported Model Categories:**\n- **OpenAI GPT Models**: GPT-4o, GPT-4.1, O3/O4 reasoning models\n- **Anthropic Claude Models**: Claude 3.5/3.7 Sonnet variants, Claude Opus/Sonnet 4\n- **Google Gemini Models**: Gemini 2.0/2.5 Pro and Flash models\n\n## Security\n\n- Tokens are stored securely in the user's home directory with restricted permissions (0700)\n- All communication with GitHub Copilot uses HTTPS\n- No sensitive data is logged\n- Automatic token refresh prevents long-lived token exposure\n\n## Troubleshooting\n\n### Authentication Issues\n```bash\n# Re-authenticate\n./github-copilot-svcs auth\n\n# Check current status\n./github-copilot-svcs status\n```\n\n### Connection Issues\n```bash\n# Check if service is running\ncurl http://localhost:8081/health\n\n# View logs (if running in foreground)\n./github-copilot-svcs run\n```\n\n### Port Conflicts\n```bash\n# Use a different port\n# Edit ~/.local/share/github-copilot-svcs/config.json\n# Or delete config file and restart to select new port\n```\n\n## Integration Examples\n\n### Using with curl\n```bash\ncurl -X POST http://localhost:8081/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"gpt-4\",\n    \"messages\": [{\"role\": \"user\", \"content\": \"Write a hello world in Python\"}],\n    \"max_tokens\": 100\n  }'\n```\n\n### Using with OpenAI Python Client\n```python\nimport openai\n\n# Point OpenAI client to the proxy\nclient = openai.OpenAI(\n    base_url=\"http://localhost:8081/v1\",\n    api_key=\"dummy\"  # Not used, but required by client\n)\n\nresponse = client.chat.completions.create(\n    model=\"gpt-4\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello, world!\"}]\n)\nprint(response.choices[0].message.content)\n```\n\n### Using with LangChain\n```python\nfrom langchain.llms import OpenAI\n\nllm = OpenAI(\n    openai_api_base=\"http://localhost:8081/v1\",\n    openai_api_key=\"dummy\"  # Not used\n)\nresponse = llm(\"Write a hello world in Python\")\nprint(response)\n```\n\n## Development\n\n### Project Structure\n```\ngithub-copilot-svcs/\n├── main.go        # Main application and CLI\n├── auth.go        # GitHub Copilot authentication\n├── proxy.go       # Reverse proxy implementation\n├── server.go      # Server utilities and graceful shutdown\n├── transform.go   # Request/response transformation\n├── cli.go         # CLI command handling\n├── go.mod         # Go module definition\n└── README.md      # This documentation\n```\n\n### Building from Source\n```bash\ngit clone \u003crepository\u003e\ncd github-copilot-svcs\nmake build\n# or manually:\ngo mod tidy\ngo build -o github-copilot-svcs\n```\n\n### Running Tests\n```bash\nmake test\n# or manually:\ngo test ./...\n```\n\n## License\n\nApache License 2.0 - see LICENSE file for details.\n\nThis is free software: you are free to change and redistribute it under the terms of the Apache 2.0 license.\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Test thoroughly\n5. Submit a pull request\n\n## Support\n\nFor issues and questions:\n1. Check the troubleshooting section\n2. Review the logs for error messages\n3. Open an issue with detailed information about your setup and the problem\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprivapps%2Fgithub-copilot-svcs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprivapps%2Fgithub-copilot-svcs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprivapps%2Fgithub-copilot-svcs/lists"}