Connecting a Custom OpenAI-Compatible API to an AI Coding Assistant: Setup Steps and Troubleshooting
Many local AI coding assistants connect to the official model service by default. This guide explains how to connect one to a custom OpenAI-compatible endpoint, including which fields to fill in, where to find the model ID, how to verify the connection, and how to diagnose common errors.
1. Background and Use Cases
Many local AI coding assistants connect to the official model service by default. In practice, developers often want to connect a model service they manage themselves, such as an internal inference gateway for a team, or any model endpoint that supports the OpenAI Chat Completions protocol. Most mainstream clients offer a “custom model provider” option. As long as an endpoint is compatible with the OpenAI protocol, meaning it accepts POST {base_url}/chat/completions with request and response structures that follow the OpenAI specification, it should in principle work with these clients.
This article documents a complete integration: what to enter in each field, where to get the model ID, how to verify connectivity, and how to quickly identify the cause of common errors. The same approach applies to other clients of this type.
2. Three Things to Prepare Before You Start
Most integration failures come from the preparation stage. Before you configure anything, confirm the following three items.
1. API Key
- Create a dedicated key in the admin console of your model service. Do not reuse a high-privilege management token. If the key leaks, the damage stays limited.
- Set a low spending limit on this key. Raise it gradually after the integration works, so debugging does not cause unexpected charges.
- Never put the key in screenshots, public repositories, or public channels. Also check the file permissions on any local configuration file that stores it.
2. Model ID
This is the most common source of errors. Copy the exact model ID from the provider’s model list or model catalog. Keep three points in mind:
- A group name is not a model ID. Groups are a billing or permission concept. The request parameter must contain the fully qualified ID of the model itself.
- The model names built into the client often do not match. The default names in the dropdown usually correspond to the official service. If model detection fails when you use a third-party endpoint, this mismatch is the likely cause.
- Model IDs are usually case-sensitive and often include a version suffix. Copy and paste the ID rather than typing it by hand.
3. Endpoint URL
An OpenAI-compatible endpoint usually exposes a base URL. The full API address is the /chat/completions path under that base URL. For example:
Base URL: https://your-gateway.example.com/v1Full endpoint: https://your-gateway.example.com/v1/chat/completions
Check what each field expects. If a field is labeled “Base URL,” enter the base URL. If it is labeled “Endpoint” or “Full endpoint,” enter the full path. Entering the full path in one field and the base URL in the other, or entering the wrong form in either, causes the path to be appended twice. The typical symptom is a 404 error.
3. Configuration Steps
Start the local client from the command line. This is usually done with a command such as npx <package> web, which opens a local port in your browser, for example http://127.0.0.1:3080. Then follow these steps:
- Go to Settings → Models → Add model provider → Custom model API.
Do not change the key on the default official provider card. That sends requests through the wrong channel. - Fill in the fields as shown in the table below.
| Field | Example value | Notes |
|---|---|---|
| Provider ID | myprovider | Use a lowercase identifier. Do not rename it after creation, because renaming can break existing configurations. |
| Name | Custom integration | Used only for display. Any value works. |
| Base URL | your-gateway.example.com/v1 | The OpenAI-compatible root address. Do not include /chat/completions. |
| Protocol | OpenAI Chat Completions | Select the protocol the endpoint actually uses. |
| API Key | Dedicated key | Start with a low spending limit. |
- Click the button to fetch available models to run a probe. If the probe fails, the model ID or the URL path is the most likely cause. You can then add the model ID manually and save.
- Start a new conversation and select the model you just configured. Configuration changes usually take effect on the next request. You do not need to restart the service.
4. Verify Connectivity: Configuring Is Not Enough
After you save the configuration, run the checks below in order, from basic to advanced.
Round 1: Basic connectivity. Send a fixed instruction, such as “Reply only with: connection successful.” If you get the correct reply, the key, URL, and model ID work together.
Round 2: Streaming output. Send “Output the numbers 1 to 5, one per line.” Check that the content arrives in parts and that the stream ends normally. Some compatible endpoints work with non-streaming requests but fail with streaming, or the reverse. This step reveals that difference.
Round 3: Tool calling (required for coding use). In an isolated test directory, check that the client can complete tool calls such as reading files and editing code. Some models do not support function calling at all. In that case the cause is the model’s capabilities, not the configuration.
Round 4: Reconciliation. Return to the provider’s admin console and check that the model name, timestamp, status code, and charged amount for your requests match what you sent. This step catches hidden problems, such as requests reaching a different model than expected or a billing group that does not match your setup.
5. Match Errors to Their Causes
When you see an error, check the status code first, then use the table below to find the cause.
| Symptom | What to check first |
|---|---|
| 401 | Whether the key is valid and unexpired. Whether you used a key from the official service by mistake. Mixing keys between the two services is a common error. |
| 403 | Whether the key’s group or permissions include this model. Whether an IP allowlist blocks your address. |
| 404 | Whether the final request path is correct, especially whether the URL path is appended twice. Whether the model ID exists and is spelled exactly right. |
| 429 | Whether you have exceeded the concurrency limit or used up your quota. Reduce concurrency or wait for the quota to reset. |
| 5xx or timeout | Record the time and the request ID, then retry later or switch temporarily to a channel you have already verified. Do not retry without limit, because that can amplify the failure. |
One scenario is easy to misdiagnose: chat works, but tool calling fails. In this case the key, network, and path are usually fine. Check whether the model supports tool calling and whether your parameters match the required structure. This is a difference in model capability, so do not troubleshoot the key or configuration.
6. Summary
Connecting a custom OpenAI-compatible endpoint is straightforward. Get three things right: the key, the model ID, and the base URL. Select the correct protocol, and make sure the path is not appended twice. Then confirm the setup in four steps: basic reply, streaming, tool calling, and reconciliation. Map common errors to their status codes, and most problems can be located within minutes. Using a dedicated key, starting with a low spending limit, and reconciling usage regularly keep a custom integration both flexible and secure.
