Last reviewed: November 6, 2026 (Asia/Shanghai); sources fetched November 6 UTC.
Direct answer
Connect CodeCompanion.nvim to CometAPI by extending its openai_compatible HTTP adapter, giving the adapter a distinct name, and selecting it under interactions.chat. Set env.url to the CometAPI HTTPS origin, host api.cometapi.com with no path, and set env.chat_url to /v1/chat/completions. Supply a CometAPI credential through a protected runtime lookup and declare an exact current text model in both schema.model.default and schema.model.choices.
The URL split matters. The CodeCompanion compatible-provider guide
says its adapter appends the chat path to the server origin. The CometAPI quickstart
documents the resulting operation as POST /v1/chat/completions. Copying an SDK base URL ending in /v1 into this adapter’s env.url would duplicate that segment.
Start with non-streaming text chat, tools and images disabled, and explicit model choices. This establishes a small configuration to inspect before adding editor actions or agent capabilities.
Who this is for
Use this guide if you already manage a Neovim configuration and want CodeCompanion’s chat buffer to use CometAPI. CodeCompanion’s current installation reference requires Neovim 0.12 or later, curl, and plenary.nvim. Follow its release-pinning advice and check that the documentation matches your installed release before merging the configuration below.
You also need a CometAPI credential and an exact model ID suitable for the Chat Completions route. The preparation environment had no Neovim or Lua executable. This configuration was reviewed against the fetched references but was not executed in CodeCompanion; no authenticated generation or completed editor integration is claimed. The workflows below are acceptance instructions for your installation.
Key takeaways
- Extend
openai_compatiblefor this Chat Completions setup and name the resulting adaptercometapi. - Keep the server origin and operation path separate so the composed URL contains
/v1once. - Set both the model default and choices; a default alone still permits a model-picker lookup.
- Use a dedicated credential lookup with a fixed missing-key error.
- Verify plain text before adding streaming, tools, images, or other interactions.
- Inspect context and diagnostics locally; keep credentials and conversation content out of shared evidence.
Contract details to verify
Choose a current text model using the CometAPI catalog reference
. It documents public GET /api/models access without an authorization header. Check the exact ID, model type, capability metadata, endpoint hints, and whether the entry is marked upcoming. Endpoint hints can have different representations, including a JSON-encoded string, so inspect the actual record.
Set the nonsecret process variable COMETAPI_MODEL to the ID you selected. A catalog entry helps choose a route; it does not establish your account’s access or prove that every optional parameter works. Preserve the selection date alongside the installed CodeCompanion version.
| Setting | Value for this setup | Reason |
|---|---|---|
| Adapter key | cometapi | Joins the registered adapter to the chat selection |
| Adapter parent | openai_compatible | Implements the Chat Completions request family |
env.url | HTTPS origin at api.cometapi.com | Supplies the origin without a version suffix |
env.chat_url | /v1/chat/completions | Supplies the complete operation path |
| Model default and choices | Same verified model ID | Keeps selection explicit and avoids model-list discovery |
| Key lookup | COMETAPI_KEY through a function | Keeps the value outside the configuration file |
| Adapter options | Streaming, tools, and vision disabled | Limits the initial capability set |
CodeCompanion documents /v1/models as the compatible adapter’s default discovery path. CometAPI separately documents its public catalog at /api/models. This setup avoids depending on the adapter’s discovery endpoint by supplying both default and choices, as the compatible-provider guide recommends. It makes no assertion about whether another model-list route is available to your account.
Configure the adapter
Make the credential available privately to the process that launches Neovim. Set COMETAPI_MODEL to the selected ID, then merge this into the configuration that runs after CodeCompanion loads. Consolidate it with your existing setup call rather than adding a competing second setup.
Before running the example, replace COMETAPI_ORIGIN_FROM_DOCS with the origin from the CometAPI quickstart
: use the HTTPS scheme and host api.cometapi.com, with no path or trailing slash. The placeholder is a Lua string to replace, not an environment-variable expression. Keep the separate chat_url unchanged.
local model = os.getenv("COMETAPI_MODEL")
assert(type(model) == "string" and model:match("%S"),
"Set COMETAPI_MODEL to a verified text model ID")
local function cometapi_key()
local key = os.getenv("COMETAPI_KEY")
assert(type(key) == "string" and key:match("%S"),
"COMETAPI_KEY is missing")
return key
end
require("codecompanion").setup({
adapters = {
http = {
cometapi = function()
return require("codecompanion.adapters").extend(
"openai_compatible", {
formatted_name = "CometAPI text",
env = {
url = "COMETAPI_ORIGIN_FROM_DOCS",
chat_url = "/v1/chat/completions",
api_key = cometapi_key,
},
schema = {
model = {
default = model,
choices = { model },
},
},
opts = {
stream = false,
tools = false,
vision = false,
},
}
)
end,
},
},
interactions = {
chat = {
adapter = "cometapi",
},
background = {
chat = {
opts = {
enabled = false,
},
},
},
},
})
The HTTP adapter reference
documents function-based environment values resolved for requests. Here, the function reads only COMETAPI_KEY and raises a fixed error for an absent or whitespace-only value. The model is captured when configuration loads; change it through trusted process configuration and restart Neovim before checking another model.
The explicit key override also avoids the adapter’s documented default lookup of OPENAI_API_KEY. Do not omit it merely because another provider already works in your editor. Follow the repository boundary in keeping CometAPI keys out of tutorial repositories
: configuration may contain variable names, while credential values remain private.
According to the compatible-provider guide, tools = false omits tool definitions, and vision = false excludes image input. Those options apply across the adapter rather than separately to each model. This example also disables the chat-title background interaction described in the chat-buffer guide
. Review any extensions or custom callbacks already present in your own configuration before treating the example as your complete request inventory.
Tool disabling does not remove text you manually attach. Buffer references, file attachments, rules, and conversation history can still become model input. Use a disposable directory and harmless content for the first check. Configure inline, command, or other interactions separately if you later want them to use this adapter.
Happy-path operator workflow
Run :checkhealth codecompanion and resolve missing requirements first. Then open a fresh chat with :CodeCompanionChat. The chat-buffer guide documents ga for selecting an adapter and model. Confirm the displayed adapter is CometAPI text and the selected model is the exact ID you configured.
Before sending, press gd to inspect the debug window. CodeCompanion says it shows adapter settings, context, and the full message history, including hidden messages. Check it locally for unintended context; a debug-window export can expose more than the visible chat. Close it without changing the settings for this first run.
Send a short prompt such as:
Reply with NEOVIM_ROUTE_OK and one short sentence about a text editor.
The guide documents <CR> in normal mode or <C-s> as send actions. Require a completed, nonempty text reply with the expected adapter and model still selected. Judge completion and the selected configuration; a requested marker is a convenient fixture, not evidence of deterministic model behavior.
Where approved diagnostics expose the request destination, confirm the host and complete Chat Completions path without saving authorization data or request bodies. If destination or status is unavailable, record it as unknown. A visible response alone cannot establish every transport detail.
Retain the observation time, Neovim version, pinned plugin release or commit, adapter key, model ID, endpoint family, completion verdict, and numeric status when exposed. These checks establish basic chat for that combination. They leave streaming, tool execution, images, and inline edits for separate acceptance work.
For another editor’s configuration contract, compare the Zed integration guide . Translate each setting deliberately: a field named API URL can expect a different URL component in another client.
Error-path operator workflow
Use the same disposable configuration for a controlled missing-key check. Launch a separate Neovim process without COMETAPI_KEY, while retaining the verified model setting. Open a new chat and attempt the harmless prompt. Require the fixed missing-key error and verify through an approved request counter or transport diagnostic that no generation was dispatched. If you cannot observe dispatch, retain that limitation instead of recording a zero-request result.
Restore the credential privately and restart the test process before the live happy path. Never remove a key from a shared production process just to create a fixture.
| Failure stage | First check | Evidence to retain |
|---|---|---|
| Configuration loading | Plugin release, adapters.http, and interactions.chat structure | Fixed local error and version |
| Missing model | COMETAPI_MODEL in the launching process | Configuration rejected before chat setup |
| Missing key | Dedicated lookup and the process environment | Missing-key verdict; dispatch observation if available |
| Authentication rejected | Active adapter and private credential source | Numeric status when exposed; sanitized category |
| Model or parameter rejected | Exact ID, route hints, and inherited adapter settings | Rejected field name when safe; configuration version |
| Incomplete or stalled reply | Completion state and elapsed time | Outcome uncertain; no assumed successful result |
Stop after a failure, correct one identified cause, and repeat only the relevant small check. A timeout or local stop leaves uncertainty about remote execution; do not repeatedly regenerate the same request to troubleshoot configuration.
Avoid turning on debug logging for ordinary evidence collection. The compatible-provider guide explicitly says DEBUG logging retains request-body files on disk. If a controlled diagnostic run requires it, use harmless content and inspect the retained artifacts locally before sharing anything. Exclude credentials, environment dumps, complete errors that echo content, prompts, generated answers, and attached source files from the evidence record.
Failure modes
The endpoint contains /v1/v1. Restore the origin-only env.url and the separate chat path. Copying the SDK base URL into a differently defined setting causes this mismatch.
The model picker requests an unwanted model list. Check that choices remains present alongside default. CodeCompanion says setting only the default still calls the discovery endpoint when opening the picker.
Models from another compatible provider appear. The compatible-provider guide documents a shared model cache across these adapters. Explicit choices on each adapter avoid relying on that shared discovery list; an unexpected picker entry is a reason to inspect configuration before sending.
The wrong API family is used. CodeCompanion’s HTTP reference distinguishes its current openai Responses adapter from the Chat Completions adapters. Preserve openai_compatible for this procedure and revalidate the complete contract before changing families.
Chat works, so tools are enabled immediately. Text success establishes no tool-execution result. Confirm model-and-route support, define a separate capability configuration, and test a harmless tool workflow before depending on it. Adapter-wide options also mean a mixed-capability model list needs deliberate separation.
A startup setting is mistaken for an editor-wide routing rule. This example selects the chat interaction. Other configured interactions and extensions need their own destination and credential checks.
FAQ
Why does this use an origin without /v1?
CodeCompanion’s compatible adapter appends chat_url, whose default already contains /v1. CometAPI’s SDK examples use a base URL defined differently. The resulting operation must use HTTPS, host api.cometapi.com, and path /v1/chat/completions.
Can CodeCompanion discover the model automatically?
Its compatible adapter supports discovery, but this setup supplies a reviewed default and choices. That avoids depending on the default discovery route and the documented shared cache during the first integration check.
Does disabling tools prevent source text from leaving Neovim?
Manually added editor context and conversation history can still be sent. Inspect the context and hidden messages before using private project material, even when tool definitions are disabled.
Can I enable streaming later?
The adapter supports a streaming option and CometAPI documents SSE for streaming Chat Completions. Verify that combination separately with incremental arrival, completion, and interruption checks before relying on it.
Reader next step
Pin a compatible CodeCompanion release, choose one current CometAPI text model, and apply the named adapter in a disposable Neovim configuration. Complete the missing-key check and the plain-text happy path, retaining only observed operational metadata. Keep this baseline before adding another capability.
If you need an account or credential for that check, Start with CometAPI , then return to the same focused setup and acceptance procedure.
Sources checked
Six primary documentation pages were fetched successfully on November 6, 2026 UTC:
- CodeCompanion: Connecting an OpenAI-Compatible Provider — URL composition, credential resolution, model choices, capability switches, shared-cache limitations, and DEBUG body retention.
- CodeCompanion: Configuring HTTP Adapters — adapter registration, interaction selection, function-based environment values, and API-family distinctions.
- CodeCompanion: Installation — current requirements, release-pinning advice, and health checks.
- CodeCompanion: Using the Chat Buffer — chat command, send actions, adapter selection, debug-window contents, context, and optional background titles.
- CometAPI: OpenAI-compatible API quickstart — server base, bearer authentication, Chat Completions, completed text, and streaming distinction.
- CometAPI: List available models — public catalog access, model IDs, capabilities, and variable endpoint metadata.
These maintained technical references support an evergreen integration task; this article makes no release announcement. The conservative capability settings, credential guard, test sequence, and evidence fields are recommendations derived from those contracts. They are not recorded editor-test results or provider service promises.