How to connect VS Code to Apily
Connect the official Claude Code or Codex extensions, or built-in VS Code Chat, to Apily. These are three separate clients, each with its own settings, API protocol and way of passing the key.
Claude Code: official Anthropic extension
Install the extension Claude Code by Anthropic (`anthropic.claude-code`). No separate CLI installation is needed. The extension requires VS Code 1.94 or later.
Open the command palette → Preferences: Open User Settings (JSON). Merge these fields into your existing settings without creating a second root JSON object. If the `claudeCode.environmentVariables` array already exists, merge its entries. Replace `YOUR_APILY_API_KEY` with your own key.
{
"claudeCode.disableLoginPrompt": true,
"claudeCode.useTerminal": false,
"claudeCode.environmentVariables": [
{ "name": "ANTHROPIC_BASE_URL", "value": "https://api.apily.pro" },
{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "YOUR_APILY_API_KEY" },
{ "name": "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY", "value": "1" },
{ "name": "CLAUDE_CODE_GATEWAY_MODEL_DISCOVERY_TIMEOUT_MS", "value": "10000" },
{ "name": "ANTHROPIC_MODEL", "value": "claude-haiku-5-5" },
{ "name": "ANTHROPIC_DEFAULT_HAIKU_MODEL", "value": "claude-haiku-5-5" },
{ "name": "ANTHROPIC_DEFAULT_SONNET_MODEL", "value": "claude-sonnet-5-5" },
{ "name": "ANTHROPIC_DEFAULT_OPUS_MODEL", "value": "claude-opus-5-5" },
{ "name": "ANTHROPIC_DEFAULT_FABLE_MODEL", "value": "claude-fable-5-1" }
]
}- Run
Developer: Reload Window, thenClaude Code: Open in New Tab. - Open a trusted test folder, not a project containing confidential code.
- Choose a Claude model in the model picker and send:
Reply with exactly OK. Do not use tools.
On startup, the extension loads the Apily catalog and adds available IDs containing `claude` or `anthropic` to the list. Discovery runs at startup, not continuously: reload the window after catalog changes. At the time of testing, `claude-fable-5-1`, `claude-haiku-5-5`, `claude-opus-5-5` and `claude-sonnet-5-5` were shown.
Codex: custom Responses provider
Install the Codex extension by OpenAI (`openai.chatgpt`). Codex uses the Responses API; Chat Completions support alone is not enough. The extension includes the Codex runtime, so no separate CLI installation is needed.
In the Codex panel, open the settings menu → Open config.toml or edit `~/.codex/config.toml` (Windows: `%USERPROFILE%/.codex/config.toml`). If `CODEX_HOME` is set, the file is in that folder. Merge the settings without duplicating keys or tables.
model = "gpt-6.1-terra"
model_provider = "apily"
[model_providers.apily]
name = "Apily"
base_url = "https://api.apily.pro/v1"
env_key = "APILY_API_KEY"
wire_api = "responses"
requires_openai_auth = false
supports_websockets = false`model` and `model_provider` must stay at the root level before the `[model_providers.apily]` heading. `env_key` is the environment variable name, not the key itself. Requests go to `https://api.apily.pro/v1/responses` over HTTP/SSE; WebSockets are disabled.
Pass the key to the VS Code process
Fully close all VS Code windows and launch it from an external terminal. A variable set only in the integrated terminal does not change the extension's environment. These examples read the key without displaying it or putting it in command arguments.
read -rsp 'Apily API key: ' APILY_API_KEY; printf '\n'
export APILY_API_KEY
code .
unset APILY_API_KEYread -rs 'APILY_API_KEY?Apily API key: '; printf '\n'
export APILY_API_KEY
code .
unset APILY_API_KEYOn macOS, first enable `code` using Shell Command: Install 'code' command in PATH.
$secret = Read-Host 'Apily API key' -AsSecureString
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secret)
try {
$env:APILY_API_KEY = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr)
code .
} finally {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr)
Remove-Item Env:APILY_API_KEY -ErrorAction SilentlyContinue
$secret.Dispose()
}Add the model to the Codex picker
Run Codex: Open Codex Sidebar, start a new local chat and send Reply with exactly OK. Do not use tools.. The tested model is gpt-6.1-terra; in the interface it may appear as Custom. Requests are charged to your Apily balance, not a ChatGPT subscription.
To make it appear in the model picker, download the local Codex catalog for GPT 6.1 Terra and add its absolute path at the root level of `config.toml`, before `[model_providers.apily]`:
model_catalog_json = "/ABSOLUTE/PATH/apily-codex-models.json"Replace the path with the actual absolute path to the downloaded file. On Windows, forward slashes work, for example `C:/Users/Alex/Apily/apily-codex-models.json`. Then fully restart VS Code and start a new Codex chat.
Built-in VS Code Chat: Custom Endpoint
This is a separate client, not the Claude Code or Codex extension panel. Custom Endpoint is available in Stable starting with VS Code 1.122.
- Open Chat → Local → model picker → Manage Models → Add Models → Custom Endpoint. Menu labels may vary between VS Code versions.
- Add OpenAI Chat Completions:
https://api.apily.pro/v1/chat/completions, then Anthropic Messages:https://api.apily.pro/v1/messages. Enter the key for each through the interface. - Open
Chat: Manage Language Modelsand the managedchatLanguageModels.json. Merge the example below with your existing configuration.
Use the secret references created by VS Code. Replace both `REPLACE_WITH_...` placeholders with actual secret IDs from the interface; do not put the API key in JSON.
[
{
"name": "Apily · OpenAI",
"vendor": "customendpoint",
"apiKey": "${input:REPLACE_WITH_OPENAI_SECRET_ID_FROM_VSCODE}",
"apiType": "chat-completions",
"models": [{
"id": "gpt-6.1-terra",
"name": "GPT 6.1 Terra · Apily",
"url": "https://api.apily.pro/v1/chat/completions",
"toolCalling": true,
"vision": false,
"streaming": true,
"maxInputTokens": 16000,
"maxOutputTokens": 4096
}]
},
{
"name": "Apily · Anthropic",
"vendor": "customendpoint",
"apiKey": "${input:REPLACE_WITH_ANTHROPIC_SECRET_ID_FROM_VSCODE}",
"apiType": "messages",
"models": [{
"id": "claude-haiku-5-5",
"name": "Claude Haiku 5.5 · Apily",
"url": "https://api.apily.pro/v1/messages",
"toolCalling": true,
"vision": false,
"streaming": true,
"maxInputTokens": 16000,
"maxOutputTokens": 4096,
"requestHeaders": { "anthropic-version": "2023-06-01" }
}]
}
]Choose the model in Local Chat and test it with a short request: Reply with exactly OK. Do not use tools.
What was verified and official sources
- For the Claude Code extension, loading four Claude models and receiving a short Haiku response through Apily were verified.
- For Codex, the Responses configuration and a short GPT 6.1 Terra response from the CLI and extension panel were verified.
- For built-in Chat, text, streaming and tools for Chat Completions and Messages were checked at the API level; the full interface workflow was not tested.
- A short response does not confirm that all models, agent tasks, tools or long contexts work. A temporary 503 for another model does not prove that the endpoint is missing.
Documentation: Claude Code for VS Code, Anthropic gateway in VS Code, Codex IDE, Codex custom providers, VS Code Custom Endpoint.