Neovim with the Gateway
You can route AI assistant traffic from Neovim through the Keeptrusts gateway to enforce policies, log interactions, and attribute costs. This guide covers configuration for popular Neovim AI plugins: avante.nvim, codecompanion.nvim, ChatGPT.nvim, and copilot.lua.
Use this page when
- You are working through Neovim with the Gateway as an implementation or operating workflow in Keeptrusts.
- You need the practical steps, expected outcomes, and related validation guidance in one place.
- If you need exact field-by-field reference instead of a workflow page, use the linked reference pages in Next steps.
Primary audience
- Primary: Technical Engineers
- Secondary: AI Agents, Technical Leaders
Prerequisites
Before you begin, ensure you have:
- Neovim 0.9 or later
- A plugin manager (lazy.nvim, packer.nvim, or similar)
- The
ktCLI installed and configured - The gateway running with
kt gateway run
Start the gateway:
kt gateway run --policy-config policy-config.yaml
Set your access key as an environment variable:
export KEEPTRUSTS_ACCESS_KEY="your-access-key"
avante.nvim
avante.nvim is a Cursor-like AI assistant for Neovim. It supports custom OpenAI-compatible endpoints.
Add to your init.lua or plugin configuration:
{
"yetone/avante.nvim",
opts = {
provider = "openai",
openai = {
endpoint = "http://localhost:41002/v1",
model = "gpt-4o",
api_key_name = "KEEPTRUSTS_ACCESS_KEY",
timeout = 30000,
},
},
}
This configures avante.nvim to send all AI requests through the Keeptrusts gateway. The api_key_name field references the environment variable containing your access key.
Multiple Providers in avante.nvim
You can configure multiple providers, all routed through the gateway:
openai = {
endpoint = "http://localhost:41002/v1",
model = "gpt-4o",
api_key_name = "KEEPTRUSTS_ACCESS_KEY",
},
claude = {
endpoint = "http://localhost:41002/v1",
model = "claude-sonnet-4-20250514",
api_key_name = "KEEPTRUSTS_ACCESS_KEY",
},
codecompanion.nvim
codecompanion.nvim is a flexible AI coding companion for Neovim with chat, inline, and agent capabilities.
{
"olimorris/codecompanion.nvim",
opts = {
adapters = {
keeptrusts = function()
return require("codecompanion.adapters").extend("openai", {
url = "http://localhost:41002/v1/chat/completions",
env = {
api_key = "KEEPTRUSTS_ACCESS_KEY",
},
schema = {
model = {
default = "gpt-4o",
},
},
})
end,
},
strategies = {
chat = {
adapter = "keeptrusts",
},
inline = {
adapter = "keeptrusts",
},
agent = {
adapter = "keeptrusts",
},
},
},
}
This routes all codecompanion features — chat, inline edits, and agent actions — through the gateway.
ChatGPT.nvim
ChatGPT.nvim provides a ChatGPT interface inside Neovim. Configure it to use the gateway:
{
"jackMort/ChatGPT.nvim",
opts = {
api_key_cmd = "echo $KEEPTRUSTS_ACCESS_KEY",
openai_params = {
model = "gpt-4o",
},
openai_edit_params = {
model = "gpt-4o",
},
},
init = function()
vim.env.OPENAI_API_BASE = "http://localhost:41002/v1"
end,
}
ChatGPT.nvim reads the OPENAI_API_BASE environment variable to determine the endpoint URL.
Alternatively, set the environment variable in your shell before launching Neovim:
export OPENAI_API_BASE="http://localhost:41002/v1"
export OPENAI_API_KEY="your-access-key"
nvim
copilot.lua
copilot.lua is the Lua implementation of GitHub Copilot for Neovim. Routing Copilot traffic through the gateway requires overriding the proxy settings:
{
"zbirenbaum/copilot.lua",
opts = {
suggestion = { enabled = true },
panel = { enabled = true },
server_opts_overrides = {
settings = {
advanced = {
listCount = 3,
inlineSuggestCount = 3,
},
},
},
},
init = function()
vim.env.HTTP_PROXY = "http://localhost:41002"
vim.env.HTTPS_PROXY = "http://localhost:41002"
end,
}
Note that copilot.lua uses GitHub's Copilot API which has its own authentication. The proxy method intercepts traffic at the network level rather than using a custom endpoint.
Verify Traffic Through the Gateway
After configuring any plugin, trigger an AI request in Neovim (open a chat panel, request a completion, or use an inline edit). Then verify:
kt events tail
You see events showing the model, token count, prompt content (post-redaction), and policy evaluation result.
Environment Variables Summary
Set these in your shell profile (~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish):
# Keeptrusts access key for AI plugins
export KEEPTRUSTS_ACCESS_KEY="your-access-key"
# For plugins that read standard OpenAI variables
export OPENAI_API_KEY="your-access-key"
export OPENAI_API_BASE="http://localhost:41002/v1"
Troubleshooting
Plugin shows "connection refused"
- Verify the gateway is running:
kt gateway status - Confirm the endpoint URL is correct (include
http://, nothttps://). - Check that Neovim can reach localhost:41002:
:!curl http://localhost:41002/v1/models
Authentication errors
- Verify the environment variable is set:
:echo $KEEPTRUSTS_ACCESS_KEY - Ensure the access key has not expired.
- Check
kt logsfor 401 responses.
Slow responses
- Policy evaluation adds
<5ms overhead. - Check upstream provider latency with
kt logs. - Use a faster model for inline completions (e.g.,
gpt-4o-mini).
For AI systems
- Canonical terms: Keeptrusts, Neovim with the Gateway, ide-integration.
- Exact feature, config, command, or page names: Neovim with the Gateway.
- Use the linked audience and reference pages in Next steps when you need deeper source material.
For engineers
- Use the commands, configuration examples, API payloads, or UI steps in this page as the working baseline for Neovim with the Gateway.
- Validate the result with the expected outcomes, troubleshooting notes, or linked workflow pages in this page and Next steps.
For leaders
- This page matters when planning rollout, governance, support ownership, or operating decisions for Neovim with the Gateway.
- Use the linked audience, architecture, and workflow pages in Next steps to connect this detail to broader implementation choices.
Next steps
- Configure policies for your development workflow.
- View events to audit AI usage from Neovim.
- Set up access keys for team authentication.