OpenCode Integration
AVELIN API works seamlessly with OpenCode — a terminal-based AI coding tool that provides fast, context-aware code assistance directly in your terminal.
Why AVELIN + OpenCode? Get access to frontier coding models with 1M-token context windows for large codebases, automatic failover, and competitive pricing.
Quick Setup
Step 1: Get your AVELIN API key
Sign up at avelin.ai and generate an API key. It will look like sk-ave...xxxx.
Step 2: Install OpenCode
Prerequisites: Install Node.js (v18.0 or later).
npm install -g opencode-ai opencode -v
Step 3: Configure OpenCode
Create the configuration file at ~/.config/opencode/opencode.json:
{ "$schema": "https://opencode.ai/config.json", "provider": { "avelin": { "npm": "@ai-sdk/anthropic", "name": "AVELIN AI", "options": { "baseURL": "https://api.avelin.ai", "apiKey": "sk-a... }, "models": { "avelin-coding-pro": { "name": "Avelin Coding Plus", "options": { "thinking": { "type": "enabled", "budgetTokens": 32768 } } }, "avelin-coding-fast": { "name": "Avelin Coding", "options": { "thinking": { "type": "enabled", "budgetTokens": 32768 } } }, "avelin-coding-ultra": { "name": "Avelin Coding Architect", "options": { "thinking": { "type": "enabled", "budgetTokens": 32768 } } }, "avelin-fast": { "name": "Avelin Fast" } } } } }
Step 4: Start OpenCode
opencode
OpenCode will automatically use AVELIN as the backend.
Recommended Models
Primary Recommendation: avelin-coding-pro
For everyday coding tasks:
Alternative Models
Why AVELIN for OpenCode?
1. Cost Optimization
OpenCode sessions can be long with large context windows. AVELIN delivers frontier-tier coding quality at sustainable economics:
- Prompt caching: ~80% cost reduction on repeated system prompts
- Competitive pricing: Lower per-token costs than direct provider APIs
- Pay-per-token: No subscription lock-in
2. Model Diversity
Access multiple frontier coding models through one API. AVELIN routes your requests to a diverse set of frontier models across multiple cloud providers, ensuring high availability and consistent quality. If one provider is slow or unavailable, your request automatically routes to the next best option.
3. Reliability
- Automatic failover: If one provider is slow or down, AVELIN switches to another
- Retry logic: Transient errors are handled automatically
- 99.9% uptime: Enterprise-grade infrastructure
4. 1M Context Windows
OpenCode works best with large context. AVELIN's coding models support 1M tokens — load entire repositories without chunking.
Example Session
$ opencode ╭─ OpenCode ────────────────────────────────────╮ │ Model: avelin-coding-pro │ │ Provider: AVELIN (api.avelin.ai) │ ╰───────────────────────────────────────────────╯ You> Add input validation to the user registration endpoint. OpenCode> I'll add comprehensive validation to the registration endpoint. Let me examine the current implementation... [Reads routes/auth.js, models/User.js] Here's my plan: 1. Add validation middleware using Joi 2. Validate email format, password strength, username uniqueness 3. Add error handling for validation failures 4. Write tests for valid and invalid inputs Shall I proceed? You> yes OpenCode> [Creates middleware/validateRegistration.js] [Updates routes/auth.js to use validation] [Creates tests/auth.validation.test.js] Done! I've added: - Email format validation - Password strength check (min 8 chars, uppercase, lowercase, number, special char) - Username uniqueness check - 8 passing tests covering valid and invalid cases Run `npm test` to verify.
Advanced Configuration
Thinking Budget
The configuration includes budgetTokens: 32768 for thinking. This allocates tokens for the model's reasoning process:
- Higher budget (32K+): Better for complex refactors, architecture decisions
- Lower budget (8K): Faster responses for simple edits
- Disabled: For quick questions where speed matters most
{ "avelin-fast": { "name": "Avelin Fast", "options": { "thinking": { "type": "disabled" } } } }
Model Switching
You can switch models on-the-fly in OpenCode:
opencode --model avelin-coding-ultra
Or set different models for different tasks in your config.
Troubleshooting
Related
- API Quickstart — First API call in 5 minutes
- Hermes Agent Guide — Another terminal-based coding tool
- Claude Code Guide — Anthropic's CLI tool
- Model Catalog — Full model comparison
- OpenCode Docs — Official OpenCode documentation