ragflow icon indicating copy to clipboard operation
ragflow copied to clipboard

[Question]: Setup Ollama with "KeyError('base_url')" error

Open mobguang opened this issue 6 months ago • 7 comments

Self Checks

  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report (Language Policy).
  • [x] Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) (Language Policy).
  • [x] Please do not modify this template :) and fill in all the required fields.

Describe your problem

Hello,

I launched Ragflow nightly version by docker in M2 ultra machine. The "KeyError('base_url')" error reported when I tried add LLM with Ollam.

Image

The Ollama is accessible, please refer to following screenshot. Image

Could you please provide the solution? Thanks.

mobguang avatar Jun 16 '25 08:06 mobguang

The "KeyError('base_url')" happens when the Ollama LLM config in Ragflow is missing the required base_url field. Even if you fill in the base URL in the UI, this error can occur if the API-Key field is left blank due to a known bug. The quick fix is to enter any value (even a random string) in the API-Key field when adding the Ollama model—this will let the model register correctly and avoid the KeyError. This workaround is confirmed by both users and maintainers and is documented in recent issues and discussions (source, source, source).

Also, make sure your base URL is set to http://host.docker.internal:11434/v1 (which you already have), and that Ollama is accessible from inside the Ragflow Docker container (source). If you still see issues, double-check that you’re running the latest nightly Docker image, as some related bugs were fixed in recent versions (source).

Let me know if this resolves it!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar Jun 16 '25 08:06 dosubot[bot]

@dosu,

I entered the random string in API-Key input field, but it not work. The console output as following:

2025-06-16 16:29:30,667 INFO 32 172.18.0.6 - - [16/Jun/2025 16:29:30] "GET /v1/user/info HTTP/1.1" 200 - 2025-06-16 16:29:30,671 INFO 32 172.18.0.6 - - [16/Jun/2025 16:29:30] "GET /v1/system/version HTTP/1.1" 200 - 2025-06-16 16:29:30,677 INFO 32 172.18.0.6 - - [16/Jun/2025 16:29:30] "GET /v1/user/tenant_info HTTP/1.1" 200 - 2025-06-16 16:29:30,713 INFO 32 172.18.0.6 - - [16/Jun/2025 16:29:30] "GET /v1/llm/factories HTTP/1.1" 200 - 2025-06-16 16:29:30,715 INFO 32 172.18.0.6 - - [16/Jun/2025 16:29:30] "GET /v1/llm/my_llms HTTP/1.1" 200 - 2025-06-16 16:29:30,717 INFO 32 172.18.0.6 - - [16/Jun/2025 16:29:30] "GET /v1/tenant/list HTTP/1.1" 200 - 2025-06-16 16:29:49,724 INFO 39 task_executor_24ef5b1d6505_0 reported heartbeat: {"name": "task_executor_24ef5b1d6505_0", "now": "2025-06-16T16:29:49.721+08:00", "boot_at": "2025-06-15T23:23:45.416+08:00", "pending": 0, "lag": 0, "done": 4, "failed": 0, "current": {}} 2025-06-16 16:30:03,429 ERROR 32 'base_url' Traceback (most recent call last): File "/ragflow/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request rv = self.dispatch_request() File "/ragflow/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] File "/ragflow/.venv/lib/python3.10/site-packages/flask_login/utils.py", line 290, in decorated_view return current_app.ensure_sync(func)(args, **kwargs) File "/ragflow/api/utils/api_utils.py", line 172, in decorated_function return func(_args, **_kwargs) File "/ragflow/api/apps/llm_app.py", line 222, in add_llm mdl = ChatModel[factory]( File "/ragflow/rag/llm/chat_model.py", line 856, in init self.client = Client(host=kwargs["base_url"]) if not key or key == "x" else Client(host=kwargs["base_url"], headers={"Authorization": f"Bearer {key}"}) KeyError: 'base_url'

mobguang avatar Jun 16 '25 08:06 mobguang

The persistent KeyError('base_url') is due to a mismatch between the config keys: Ragflow expects api_base everywhere in the backend and UI, but the error occurs if base_url is missing or not mapped to api_base internally. This is a known schema inconsistency—there’s no fallback or aliasing between these keys in the code, so if api_base isn’t set correctly, you’ll get this error even if you fill in the UI fields source.

To work around this:

  • Make sure you are entering the base URL in the field labeled api_base (not base_url) in the UI. The correct value for Docker is http://host.docker.internal:11434/v1 source.
  • Double-check that the field is not being auto-corrected or renamed by your browser or any autofill.
  • If you are editing config files or using the API directly, always use api_base as the key.
  • If you’re comfortable editing code, you can patch the backend to use base_url = config.get("api_base") or config.get("base_url") to avoid this class of error.

Also, ensure Ollama is running with OLLAMA_HOST=0.0.0.0 and the port is exposed, and use your host’s actual IP address if host.docker.internal doesn’t work in your Docker setup source.

There’s no recent patch in the codebase to harmonize these keys, so this workaround is necessary for now. Let me know if you need help checking the actual request payload or want guidance on a code-level fix.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar Jun 16 '25 08:06 dosubot[bot]

I confirm exactly the same problem, the suggested workaround does not help. The error persists. The latest nightly release v0.19.x-161-gf7074037 full and ollama:0.9.0

vab072 avatar Jun 16 '25 15:06 vab072

I did a reinstall. That fixed this issue.

Promethean-Pty-Ltd avatar Jun 17 '25 00:06 Promethean-Pty-Ltd

I did a reinstall. That fixed this issue.

@Promethean-Pty-Ltd ,

May I know what configuration you set:

  1. What OS type you used, Mac or Windows?
  2. Whether you launched Ragflow by docker?
  3. What Ragflow version you launched, v0.19.0 or nightly?

Thanks.

mobguang avatar Jun 17 '25 03:06 mobguang

Pull the nightly version of docker image again.

KevinHuSh avatar Jun 18 '25 03:06 KevinHuSh

Thank you, my problem is fixed

vab072 avatar Jun 19 '25 05:06 vab072

Image

  1. 确认使用了 infiniflow/ragflow:nightly-slim 镜像
  2. ollama 运行正常

docker安装, 重新安装了一遍, 还是创建失败

Wang-0122 avatar Jul 15 '25 08:07 Wang-0122

Try: 172.17.0.1:11434

KevinHuSh avatar Jul 15 '25 10:07 KevinHuSh