This setup creates an OpenRouter-compatible API server that wraps web-based AI models, making them usable with tools like GitHub Copilot, Cline, and any OpenAI-compatible client.
- Install dependencies:
pip install fastapi uvicorn selenium langchain webdriver-manager- Start the server:
python openrouter_server.py- Server runs on:
http://localhost:8000
Unfortunately, GitHub Copilot doesn't support custom endpoints directly. However, you can:
- Use Continue.dev extension instead (supports custom endpoints)
- Use Cline (formerly Claude Dev) which supports OpenAI-compatible APIs
- Install Cline extension in VS Code
- Open Cline settings
- Configure API:
- Provider: OpenAI Compatible
- Base URL:
http://localhost:8000/v1 - API Key:
dummy-key(not used but required) - Model:
google/gemini-pro
- Install Continue extension
- Edit
~/.continue/config.json:
{
"models": [
{
"title": "Gemini Pro (Web)",
"provider": "openai",
"model": "google/gemini-pro",
"apiBase": "http://localhost:8000/v1",
"apiKey": "dummy-key"
}
]
}- Go to Settings → Models
- Add custom model:
- Provider: OpenAI Compatible
- Base URL:
http://localhost:8000/v1 - Model:
google/gemini-pro - API Key:
dummy-key
import openai
client = openai.OpenAI(
api_key="dummy-key",
base_url="http://localhost:8000/v1"
)
response = client.chat.completions.create(
model="google/gemini-pro",
messages=[{"role": "user", "content": "Hello!"}]
)google/gemini-pro- Google's Gemini Pro via AI Studiogoogle/gemini-pro-vision- Gemini Pro with vision (same backend for now)
To add support for other web-based models:
- Create new LLM wrapper (similar to
GoogleAIStudioLLM) - Add to model registry in
openrouter_server.py - Update
get_llm_instance()to handle new models
Example for ChatGPT:
# In openrouter_server.py
AVAILABLE_MODELS["openai/gpt-4-web"] = {
"id": "openai/gpt-4-web",
"name": "GPT-4 Web",
"description": "ChatGPT via web interface"
}
# Create ChatGPTWebLLM class similar to GoogleAIStudioLLMSince web models require login:
- First run: Set
headless=FalseinGoogleAIStudioLLM - Manual login: Browser opens, log in manually
- Session persistence: Browser stays logged in
- Production: Implement automated login (advanced)
- Slower than APIs: Web scraping adds latency
- Rate limits: Web interfaces have stricter limits
- Fragile: UI changes can break selectors
- Authentication: Requires manual login initially
- Check if port 8000 is available
- Install missing dependencies
- Check if you're logged into the web interface
- Verify selectors are still valid
- Check browser console for errors
- Ensure server is running on correct port
- Check firewall settings
- Verify API endpoint configuration
- Server runs locally only by default
- No real API key validation (uses dummy keys)
- Web sessions are browser-based
- Consider VPN if accessing from remote tools
- Keep browser sessions alive
- Add connection pooling for multiple requests
- Implement caching for repeated queries
- Use headless mode in production