-
-
Notifications
You must be signed in to change notification settings - Fork 354
Description
Pre-submission checklist
- I have read the documentation
- I have updated the plugin and all dependencies to the latest versions
- I have searched for existing issues and discussions
- My issue is not a minor or cosmetic quirk (e.g., formatting, spacing, or other non-functional details)
Neovim version (nvim -v)
0.11.5
Operating system/version
Fedora Linux 42
Adapter and model
Ollama - not depend on model
Describe the bug
Hello! This is my first issue, so I'm not entirely sure if this is a bug or a feature request.
I believe the
headersfield described in the adapter documentation (@field headers table The headers to pass to the request) does not work as expected for model fetching requests. It took me some time to find the cause.
I'm not yet really familiar with Lua, so the proposed fix might be incorrect.I love this plugin, and if I've done something wrong with this report or the minimal.lua, I apologize in advance.
When I do:
Configure custom headers on the Ollama adapter (e.g., for authentication with a reverse proxy):
require("codecompanion").setup({
adapters = {
ollama = function()
return require("codecompanion.adapters").extend("ollama", {
headers = {
["X-Custom-Auth"] = "my-token",
},
})
end,
},
})I observe:
Custom headers are sent on normal chat requests, but not on model fetching (/api/tags, /api/show). This breaks authenticated proxy setups.
Note: I'm aware env.api_key handles Authorization, but my proxy requires a different custom header.
But I expect:
Custom headers configured on the adapter should be included in all requests, including the model list fetch.
Possible fix:
In get_models.lua, use adapter.headers as the base for request headers:
local headers = adapter_utils.set_env_vars(adapter, adapter.headers) or {}
headers["content-type"] = headers["content-type"] or "application/json"Steps to reproduce
- Open Nvim with the provided minimal.lua
- Run
:CodeCompanionChat - See
:messageslogs
Expected behavior
The defined header, should be attached.
Screenshots or recordings (optional)
No response
minimal.lua file
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
local plugins = {
{
"olimorris/codecompanion.nvim",
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
},
config = function()
-- Patch curl to log headers before setup
local curl = require("plenary.curl")
local original_get = curl.get
curl.get = function(url, opts)
vim.print("=== CURL GET ===")
vim.print("URL: " .. url)
vim.print("Headers: " .. vim.inspect(opts.headers or {}))
return original_get(url, opts)
end
require("codecompanion").setup({
adapters = {
ollama = function()
return require("codecompanion.adapters").extend("ollama", {
env = {
url = "http://192.168.100.2:11434",
api_key = "my-secret-key",
},
headers = {
["X-Custom-Auth"] = "my-secret-token", -- Should be included
},
})
end,
},
strategies = {
chat = { adapter = "ollama" },
},
opts = {
log_level = "DEBUG",
},
})
end,
},
}
-- Leaving this comment in to see if the issue author notices ;-)
require("lazy.minit").repro({ spec = plugins })
require("nvim-treesitter")
.install({ "lua", "markdown", "markdown_inline", "yaml" }, { summary = true, max_jobs = 10 })
:wait(1800000)Log output (optional)
URL: http://localhost:11434/api/tags
Headers: {
["content-type"] = "application/json"
}
### Minimal reproduction confirmation
- [x] Yes, I have tested and provided a `minimal.lua` file that reproduces the issue