Trae with a custom OpenAI-compatible endpoint
Trae is ByteDance's AI IDE, and unlike most editors in this cluster it does not ask you to edit a JSON file, a custom model is a short form. The endpoint field is the one that stops people, because two write-ups will tell you opposite things about /v1 and both are right, for different positions of the same switch.
Trae accepts two API surfaces. Under Settings → Models → Add Model → Custom Config you choose an API format — OpenAI Chat Completions or Anthropic Messages And then supply a request URL, a model ID and a key. That is the whole form.
The trap is that the URL field is not a base URL. It is either a base URL or a full URL, and a toggle decides which. Everything that follows hangs off that one switch.
https://aicomp.ai/v1).
Create one free →
The full-URL switch decides whether /v1 belongs
Trae's own documentation describes two modes for the request address:
| Switch position | What you paste | What Trae does |
|---|---|---|
| Full URL off (the usual failure) | a base address, version segment included, no trailing slash | appends the path for the chosen API format, e.g. /chat/completions |
| Full URL on | the complete request address | appends nothing |
Read that as a rule about who owns the tail of the URL. When the switch is off, Trae owns everything after the version segment and you must not type it. When the switch is on, you own the whole address and Trae touches nothing.
This is why the two guides contradict each other. A writer who had the switch off correctly reports that the field must end in /v1 and must not carry a path. A writer who had it on correctly reports that you paste the full path including /chat/completions. Neither mentions the switch, so both look wrong to whoever reads the other first.
The doubled segment is the symptom when you get it backwards: paste https://gw.example.com/v1 with the switch on and the request goes out as-is; paste it with the path already attached and the switch off, and you get /v1/chat/completions appended to something that already ended in /chat/completions.
Decide the mode first, then type. Do not type and then try to remember.
Pick the API format before the URL
The format selector is not cosmetic, it changes what Trae appends, and therefore what your base URL should be.
- OpenAI Chat Completions targets
/v1/chat/completions. Trae's own list calls out OpenAI, DeepSeek, Kimi, GLM, OpenRouter and "some Ollama / OpenAI-compatible proxies" as the services this fits. - Anthropic Messages targets
/v1/messages, for Claude models and Anthropic-compatible proxies.
This matters for a gateway because the two formats are not interchangeable at the path level. If your endpoint serves an OpenAI-shaped surface, selecting Anthropic Messages sends the wrong path and the wrong body shape; the reply is an error that looks like an auth problem.
Set the format, then set the URL to match it. Changing the format after pasting a URL is a common way to introduce the doubled or mismatched path without editing the URL at all.
Save triggers a live check, and the failure is not diagnostic
Trae validates the key when you save. That is convenient right up to the moment it fails, because the message does not tell you which of the three fields is wrong.
When a save is rejected, the candidates are, in the order worth checking:
- The path. A doubled version segment, a trailing slash, or a path left on a field that should have been a base address. This is the most common cause and the least obvious, because the form is full of valid-looking text.
- The model ID. Trae does not fetch a model list. Whatever string you type is sent verbatim, so a display name where the API expects an ID fails as an unknown model.
- The key. Genuinely wrong, or from a different account than the endpoint expects.
Work down that list rather than editing the URL repeatedly. The path is where the fixes usually are.
The four fields people leave at defaults
Opening the advanced section of the form exposes settings that quietly change cost and behaviour:
| Field | Why it is worth setting |
|---|---|
| Context window | Some models advertise a large window but are billed or truncated differently at the top end |
| Image input | A capability flag; enabling it on a text-only model produces errors that read like request-format problems |
| Temperature / Top P / Top K | Per-model. A value tuned for one model is not a safe default for another |
Trae notes that your custom values take precedence over the model-family presets it ships. That is the useful part: setting the context window explicitly stops the IDE from guessing on your behalf.
Routing an IDE through one endpoint
An IDE is a high-volume, unfriendly client. Trae's agent mode resends the conversation on every turn, and the completion path fires continuously while you type — the two shapes that dominate a bill are the ones with the most input tokens and the smallest outputs, plus long agent loops.
A working month on this setup runs about 260k input and 30k output tokens a day, which is 5.2M input and 0.6M output across 20 working days. That ratio is the reason the two slots should not share one model: completion lives almost entirely in the input column, while the agent panel spends far more on output.
| Model | Gateway rate in / out per 1M tokens | One day | 20 days |
|---|---|---|---|
| gpt-5.6-terra | $1.00 / $6.00 | $0.44 | $8.80 |
| claude-sonnet-5 | $1.00 / $5.00 | $0.41 | $8.20 |
| deepseek-v4-pro | $0.66 / $1.98 | $0.23 | $4.62 |
| glm-5.3 | $0.70 / $2.2 | $0.25 | $4.96 |
One day = 260k input + 30k output on this page's workload. 20 days = 5.2M input and 0.6M output. Rates checked 2026-10-15 (gateway rates move with upstream promotions), so verify the current number in your dashboard before committing to a budget.
Two practical notes that follow from the table rather than from Trae itself:
- The completion slot and the agent slot do not have to be the same model. Completion tolerates a cheap fast model; the agent panel is where a stronger model pays for itself.
- Whether a given model is sensible here depends on the output-to-input multiple, not on the headline input price, the index median sits near 4×, so a model whose output rate is far above that will surprise you in an agent loop.
If you are choosing between models for this role, the <a href="/guides/cheapest-models-by-workload/">re-ranked index</a> sorts by workload shape rather than by input price, which is the comparison an IDE actually needs.
What to change if it still will not connect
Work through the list in order — each item eliminates a class of cause rather than a single guess:
- Turn the full-URL switch off and paste a base address that ends at the version segment, no trailing slash. If this connects, the switch was the whole problem.
- Confirm the API format matches the surface your endpoint serves. Open a terminal against the same base URL and call the chat route directly; if that works, the endpoint is fine and the format selector is the suspect.
- Re-copy the model ID from the endpoint's model list, not from the model's marketing page, the two differ constantly.
- Re-issue the key and paste it without surrounding whitespace.
FAQ
FAQ
Does Trae need the base URL to end in /v1?
Only in the switch-off mode. With the full-URL switch off, Trae appends the path for the chosen API format, so the version segment is yours and everything after it is Trae's — include /v1, exclude the route. With the switch on, you supply the entire address and /v1 is simply part of it.
Why do two guides give me opposite answers about the path?
Almost always because they were written against different switch positions and neither mentioned it. The rule is about ownership of the tail of the URL, not about a fixed spelling.
Can Trae use a Claude model and a GPT model at the same time?
Yes. Add each as its own custom model entry, changing the model ID and, if the surfaces differ, the API format. The endpoint and key can stay the same.
Does Trae pull the model list from my endpoint?
No. The model ID is typed by hand and sent verbatim, so it has to match the identifier the endpoint expects exactly.
Will the same configuration work for completion and agent mode?
Both use the configured model, but they stress it differently, completion is small, frequent and latency-sensitive, while agent mode is input-heavy and long-lived. It is worth pointing them at different models rather than optimising for one and living with the other.
Related
- Tools that take one endpoint (the full matrix), if Trae is not the only client you are pointing at a gateway
- Base URL not working, the doubled-path failure in general form, which is what the wrong switch position produces
- OpenAI-compatible endpoints — the request shape the OpenAI Chat Completions format targets
- Claude Code with a custom endpoint — another IDE-adjacent client with its own rule about who owns the tail of the URL
- Cursor with a custom endpoint (the same IDE class), configured through a settings screen rather than a form
- Official vs gateway prices — how the two price columns on this site are measured