RAGFlow with a Custom OpenAI-Compatible Endpoint

In short: Since v0.27.0 a provider configures as a named instance rather than a settings row. Versions 0.27.0 to 0.27.2 append a missing version segment and earlier versions do not, so writing it is the only portable value. A failed verification reports the same message for a wrong key, path, host or model. Max tokens budgets context rather than capping the reply, and zero silently becomes 8192.

RAGFlow connects to a model through a provider, and since v0.27.0 a provider is no longer a single row of settings. It is an instance you create, name, and attach models to. That change is what most older walkthroughs get wrong, and it is also the reason the same base URL can behave differently on two installs of the same product.

Pick OpenAI-API-Compatible as the provider type. It exists precisely for endpoints that are not on the shortlist of named vendors, and it is the only one that will accept an arbitrary base URL.

You need a key before the code below runs. Create an account, generate a key, and copy the base URL (https://aicomp.ai/v1). Create one free →
Check current rates → Free to sign up · $1 minimum top-up · No prepayment

Instances, not rows

Go to User settings → Model providers, find OpenAI-API-Compatible under Available models, and create an instance.

FieldValueNotes
Instance nameanything but defaultdefault is taken by the built-in entry
Base URLhttps://gw.example.com/v1must carry the version segment
API Keyyour gateway keysent as a Bearer token, scoped to this instance

One instance holds one endpoint. Separate instances are the intended way to keep a test endpoint and a production endpoint from bleeding into each other, which is why the instance name matters more than it looks: it is how you tell them apart later, both in the UI and in the model ID, which is rendered as OpenAI-API-Compatible/<instance>/<model>.

After saving, RAGFlow verifies the connection. Only then can you add models.

The /v1 rule changed at v0.27.0

This is the single most common reason a correct-looking base URL fails.

VersionWhat RAGFlow does with a base URL that has no /v1
v0.27.0 – v0.27.2appends the missing /v1 for you
earliersends it as written

The practical rule that works on every version: always write the version segment yourself. Never rely on RAGFlow to add it, and never paste a full /chat/completions URL, because that gets the operation appended to it and produces a path with the operation twice.

If you are on 0.27.0 through 0.27.2 and you wrote the version segment, the auto-append does not fire and you are fine. If you are on an earlier version and you omitted it, nothing adds it and every call 404s.

The error message tells you nothing

Saving an instance runs a test call, and when it fails the message is:

Fail to access model(OpenAI-API-Compatible/…).No valid response received

This is RAGFlow's blanket conclusion for a failed test chat. It is the same string for a wrong key, a wrong path, an unreachable host, an exhausted quota, and a model name that does not exist. Treating it as a diagnosis wastes the first hour.

What actually distinguishes the causes is the endpoint's own log and the shape of the failure:

Verification runs a chat completion, so an endpoint that only serves embeddings cannot be verified this way. Add the embedding models and use them in a knowledge base instead.

Max tokens is not a generation cap

This field is widely misread, and the misreading costs money in one direction and truncated answers in the other.

RAGFlow's Max tokens is the context budget it reserves for chat history plus retrieved chunks. It is not sent to the model, and it does not cap the model's reply. Setting it to 128 does not make answers short; it makes RAGFlow drop retrieved content to fit.

Setting it to 0 falls back to 8192. That is the quiet default that surprises people who deliberately set a small number to save money and then wonder why retrieval got worse instead.

The generation cap is a separate setting on the model row, and on many gateways it is not enforced at all.

Adding models, and the catalog prefill

Two routes in.

List models adds models RAGFlow already knows about for this provider type. If your model is not there, use Add custom model: the name must match the model ID your gateway exposes exactly, character for character. A near miss is not fixed up and not reported; the row saves and calls fail.

One behaviour worth knowing before you click: the list route can prefill the entire catalog as Chat type, including model IDs that are image or embedding models. Those rows are wrong, and they sit in the picker looking valid. Remove the ones you will not use.

Tool call is a per-model toggle. Enable it only for models your gateway lists as function-calling capable. Turning it on for a model that does not return structured tool calls makes agent runs fail in a way that reads like a prompt problem.

Where the tokens go

A RAGFlow answer is not one request per question. The query is embedded, chunks are retrieved, and the question plus every retrieved chunk plus the conversation history goes to the model on every turn.

So the input side scales with retrieval settings, not with the question. Raising the chunk count raises every turn, including the turns where the answer is one sentence. Output is a single answer per turn.

A day on this page's workload is 200k input and 40k output tokens: 4M input and 0.8M output across 20 working days. Retrieval depth and the Max tokens budget are the two levers, and both are on the input side.

Per 1M input / output tokens and a 20-day month
ModelGateway rate
in / out per 1M tokens
One day20 days
gpt-5.6-terra$1.00 / $6.00$0.44$8.80
claude-sonnet-5$1.00 / $5.00$0.40$8.00
deepseek-v4-pro$0.66 / $1.98$0.21$4.22
qwen3.8-max$1.00 / $3.00$0.32$6.40
glm-5.3$0.70 / $2.2$0.23$4.56

One day = 200k input + 40k output on this page's workload. 20 days = 4M input and 0.8M output. Rates checked 2026-10-14, gateway rates move with upstream promotions, so verify the current number in your dashboard before committing to a budget.

Across 221 catalogue models that publish both rates, the median output rate is 4.0× the input rate, and 69% of them (152 models) charge at least 4× more for output than input. The other 624 raw catalogue entries are dropped by cleaning (test entries, dated snapshots and non-chat variants) not for a missing rate. This is why an agent workload is decided on the output column, not the input one everyone quotes.

Verifying the route

  1. Choose OpenAI-API-Compatible, not a named vendor with a similar-looking URL field.
  2. Name the instance something other than default, so you can tell instances apart later.
  3. Include /v1 yourself. The auto-append only exists on 0.27.0–0.27.2 and only fires when it is missing.
  4. Never paste a URL ending in /chat/completions.
  5. Read the failure, do not trust the message. Check the gateway log to tell URL from key from model.
  6. Set Max tokens deliberately. It budgets context, not the reply, and 0 silently becomes 8192.
  7. Prune the prefilled catalog so embedding and image IDs are not sitting in the chat picker.

FAQ

FAQ

Why does saving the instance fail with "No valid response received"?

That message is RAGFlow's generic test-chat failure. It covers a wrong key, a wrong path, an unreachable host and a missing model equally. Check the gateway's log to see whether a request arrived and what it looked like.

Does the base URL need /v1?

Write it yourself. Versions 0.27.0 to 0.27.2 add it when absent and earlier versions do not, so including it is the only value that works everywhere.

Why does the model row save but every call fail?

The name in the row does not match the model ID the gateway serves. Add it as a custom model and copy the ID from the gateway's models route rather than typing it.

Does Max tokens cap how long the answer is?

No. It budgets the context RAGFlow assembles from history and retrieved chunks, and it is not sent to the model. A value of 0 falls back to 8192.

Why is an image model listed as a chat model?

The list route can prefill the whole catalog as Chat type. Those rows are not valid for chat; delete the ones you do not need.

Can I use two endpoints in one RAGFlow install?

Yes, as two instances under the same provider. Instances are independent, which is what they were introduced for.

Related

Get API access