CLI-as-API: Turn Your CLI Subscriptions into REST APIs
Use your existing Claude Code, Codex CLI, or Gemini CLI subscriptions as standard REST APIs. Point any OpenAI, Anthropic, or Google SDK at Polydev and your local CLI handles the request.
What is CLI-as-API?
CLI-as-API is a tunnel that exposes your locally-installed AI CLIs as standard REST API endpoints. If you have a Claude Code, Codex CLI, or Gemini CLI subscription, you can use them as drop-in replacements for the official APIs — no separate API key billing required.
Why? Many developers pay for CLI subscriptions (e.g. Claude Code Max at $200/mo) but also need API access for scripts, IDE integrations, and automation. CLI-as-API bridges this gap — one subscription, both interfaces.
How It Works
The request flow is simple:
- Your app sends a standard API request (OpenAI, Anthropic, or Google format) to
polydev.ai/api/v1 - Polydev validates your
pk-*key and checks rate limits - The request is queued and picked up by your local MCP process
- Your local CLI (Claude Code, Codex, Gemini) processes the prompt
- The response flows back through the tunnel in the original API format
Universal keys: A single pk-* key works with all three providers. Routing is automatic based on the model ID you request.
Getting Started
1. Create an API Key
Go to the CLI-as-API dashboard and click "Create Key". You can optionally set custom rate limits per hour, day, and month.
2. Start the Tunnel
Your Polydev MCP server acts as the tunnel. If you already have Polydev configured in any IDE (Claude Code, Cursor, Cline, etc.), the tunnel starts automatically when the MCP process runs.
3. Make Requests
Point any SDK or HTTP client at https://www.polydev.ai/api/v1 with your pk-* key:
from openai import OpenAI
client = OpenAI(
base_url="https://www.polydev.ai/api/v1",
api_key="pk-your-key-here"
)
response = client.chat.completions.create(
model="claude-opus-4-6",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)Rate Limits
Each API key has three configurable rate limit windows. You can set custom limits up to your tier maximum when creating a key.
| Window | Free | Premium |
|---|---|---|
| Per Hour | 10 | 100 |
| Per Day | 50 | 500 |
| Per Month | 500 | 10,000 |
Rate limits reset at the top of each UTC hour, midnight UTC (daily), and the first of each month. Tunnel requests also count against your monthly message quota (500 messages/month).
Supported Models
Pass any of these model IDs in your API request. The tunnel automatically routes to the correct CLI provider.
| Claude (via Claude Code) | GPT (via Codex CLI) | Gemini (via Gemini CLI) |
|---|---|---|
| claude-opus-4-6 | gpt-5.3-codex | gemini-3-pro-preview |
| claude-sonnet-4-5-20250929 | gpt-5.1-mini | gemini-2.5-flash |
| claude-haiku-4-5-20251001 | o3, o4-mini | gemini-2.5-pro |
SDK Examples
OpenAI Python
from openai import OpenAI
client = OpenAI(
base_url="https://www.polydev.ai/api/v1",
api_key="pk-your-key-here"
)
# Use any model — routes automatically
response = client.chat.completions.create(
model="claude-opus-4-6", # or gpt-5.3-codex, gemini-2.5-pro
messages=[{"role": "user", "content": "Explain quicksort"}]
)
print(response.choices[0].message.content)Anthropic Python
import anthropic
client = anthropic.Anthropic(
base_url="https://www.polydev.ai/api/v1",
api_key="pk-your-key-here"
)
message = client.messages.create(
model="claude-opus-4-6",
max_tokens=4096,
messages=[{"role": "user", "content": "Explain quicksort"}]
)
print(message.content[0].text)Google Gemini (REST)
curl https://www.polydev.ai/api/v1/google/generate \
-X POST \
-H "x-goog-api-key: pk-your-key-here" \
-H "Content-Type: application/json" \
-d '{"contents":[{"parts":[{"text":"Explain quicksort"}]}]}'curl (OpenAI format)
curl https://www.polydev.ai/api/v1/chat/completions \
-H "Authorization: Bearer pk-your-key-here" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-6",
"messages": [{"role": "user", "content": "Explain quicksort"}]
}'IDE Setup
Use CLI-as-API as a custom model provider in any IDE that supports the OpenAI API format.
Cursor
In Cursor Settings > Models > Custom API, add:
Base URL: https://www.polydev.ai/api/v1
API Key: pk-your-key-here
Model: claude-opus-4-6Cline (VS Code)
In Cline settings, select "OpenAI Compatible" as the provider:
API Provider: OpenAI Compatible
Base URL: https://www.polydev.ai/api/v1
API Key: pk-your-key-here
Model ID: claude-opus-4-6Continue (VS Code)
Add to your ~/.continue/config.json:
{
"models": [{
"provider": "openai",
"title": "Polydev CLI-as-API",
"model": "claude-opus-4-6",
"apiBase": "https://www.polydev.ai/api/v1",
"apiKey": "pk-your-key-here"
}]
}Troubleshooting
"Tunnel offline" (503)
Your Polydev MCP process isn't running. Open any IDE with Polydev configured, or check the tunnel status on the dashboard.
"Rate limit exceeded" (429)
You've hit your hourly, daily, or monthly limit. Check which window is exhausted on the dashboard and either wait for reset or adjust your key's limits.
"No matching CLI provider" (503)
The model you requested requires a CLI that isn't connected. For example, requesting a gpt-* model requires Codex CLI to be installed and detected.
"Request timed out" (504)
The CLI took longer than 120 seconds to respond. This can happen with very long prompts or complex requests. Try simplifying the prompt or check that your CLI is responsive.
Ready to get started?
Create your first API key and start using your CLI subscriptions as REST APIs.