Roo Code Base URL Configuration
How to Configure the Base URL in Roo Code for Custom API Endpoints
Configuring a custom base URL in Roo Code allows you to route AI requests through relay services, self-hosted model servers, or alternative API providers. This is essential for developers who need centralized API management, access from restricted regions, or integration with enterprise API gateways. This guide provides step-by-step instructions for configuring the base URL with various providers.
What Is the Base URL?
The base URL is the root endpoint that Roo Code sends API requests to. By default, each provider has its own base URL (e.g., https://api.openai.com/v1 for OpenAI). When you set a custom base URL, all requests are redirected to your specified endpoint instead. This endpoint must implement the same API format that Roo Code expects for the selected provider type.
Step-by-Step Configuration
- Click the Roo Code icon in the VS Code sidebar to open the panel.
- Click the settings icon (gear) at the top of the Roo Code panel.
- Select "OpenAI Compatible" from the API Provider dropdown. This is the most flexible option for custom base URLs.
- Enter your custom base URL in the Base URL field.
- Enter your API key in the API Key field.
- Enter the model identifier in the Model ID field.
- Click outside the fields to save. Configuration takes effect immediately.
// Example: Using claude4u.com relay service
Provider: OpenAI Compatible
Base URL: https://claude4u.com/v1
API Key: cr_your-relay-api-key
Model ID: claude-sonnet-4-20250514
/v1 and should NOT include /chat/completions or any other endpoint path. Roo Code appends the appropriate endpoint path automatically based on the request type. Including the full path will result in a malformed URL.Configuration for Popular Services
API Relay Service (claude4u.com)
A relay service provides unified access to multiple AI models through a single endpoint. This is the recommended setup for most developers:
Base URL: https://claude4u.com/v1
API Key: cr_your-relay-key
Model ID: claude-sonnet-4-20250514
// Switch models by changing only the Model ID:
// claude-sonnet-4-20250514 - Claude Sonnet 4
// gemini-2.5-flash - Google Gemini 2.5 Flash
// gemini-2.5-pro - Google Gemini 2.5 Pro
// gpt-4o - OpenAI GPT-4o
Local Ollama Server
Base URL: http://localhost:11434/v1
API Key: ollama (any non-empty string works)
Model ID: llama3.1:latest
// Common Ollama models:
// deepseek-coder-v2:latest - Good for coding
// qwen2.5-coder:latest - Good for coding
// llama3.1:70b - General purpose (requires 48GB+ VRAM)
Together AI
Base URL: https://api.together.xyz/v1
API Key: your-together-api-key
Model ID: meta-llama/Llama-3.3-70B-Instruct-Turbo
Groq (Fast Inference)
Base URL: https://api.groq.com/openai/v1
API Key: your-groq-api-key
Model ID: llama-3.3-70b-versatile
DeepSeek
Base URL: https://api.deepseek.com/v1
API Key: your-deepseek-api-key
Model ID: deepseek-chat
Testing Your Configuration
After configuring the base URL, verify everything works correctly:
- Quick test: Open the Roo Code chat and send "Hello, what model are you?" to confirm connectivity and model identity.
- File operation test: Ask Roo Code to create a simple test file to verify write permissions work through the configured endpoint.
- Streaming test: Ask for a longer response and verify that tokens stream in real-time rather than arriving all at once.
// Terminal test with curl to verify the endpoint:
curl -X POST https://claude4u.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer cr_your-key" \
-d '{
"model": "claude-sonnet-4-20250514",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 50
}'
Per-Mode Base URL Configuration
Roo Code allows different API configurations for different modes. This means you can use a powerful model for Code mode and a cheaper one for Ask mode:
- Open Roo Code settings.
- Switch to the mode you want to configure (e.g., Ask mode).
- Set the provider, base URL, API key, and model for that specific mode.
- Repeat for each mode that needs a different configuration.
Troubleshooting
- "Connection refused" or timeout: Verify the URL is correct and accessible. Test with curl from your terminal. Check for firewall or proxy issues.
- "Unauthorized" or "Invalid API key": Confirm the API key is correct. Some providers require specific key formats or prefixes.
- "Model not found": The Model ID does not match any model on the endpoint. Try listing models with
GET /v1/modelsto see available options. - Garbled or incomplete responses: The endpoint may not fully support the OpenAI chat completions format. Check if the provider has any known compatibility issues.
- CORS errors: This typically only affects browser-based setups. VS Code extensions make direct HTTP requests that are not subject to CORS.
Security Best Practices
- Never share screenshots of your settings that show API keys.
- Rotate API keys periodically, especially if you suspect they have been exposed.
- Use HTTPS for all remote base URLs to encrypt API traffic.
- For team environments, each developer should use their own API key rather than sharing a single key.
Get Started with 轻舟 AI
Stable, fast AI API relay — supports Claude, OpenAI, Gemini and more
Sign Up Free
轻舟 AI