docs: document LiteLLM proxy model configuration#419
Open
DivyamTalwar wants to merge 1 commit into
Open
Conversation
Issue morphik-org#170 asks how to use Morphik with a LiteLLM proxy or OpenAI-compatible endpoint. The backend already accepts api_base on registered-model entries for LiteLLM/OpenAI-compatible model definitions, but the docs did not show that path clearly. Constraint: This PR must not change runtime model defaults, secret handling, or base_url alias behavior. Rejected: Supporting base_url as a registered_models alias | that is a code behavior change and needs separate tests. Confidence: high Scope-risk: narrow Directive: Keep backend registered model examples on api_base unless code adds explicit alias normalization. Tested: .venv/bin/python TOML parse for morphik.toml and morphik.docker.toml; .venv/bin/python TOML/YAML parse for DOCKER.md fenced examples; .venv/bin/python plus bash -n for DOCKER.md bash fences; commented LiteLLM proxy example, endpoint, selector-hint, embedding-dimension, and document_analysis exclusion checks; structured exact-snippet proxy docs assertions; stale/unsafe proxy docs grep; positive proxy guidance grep; LiteLLM/logging/metadata/selector-consumer code-path grep; git diff --check. Not-tested: Live LiteLLM proxy request; documentation-only change.
DivyamTalwar
marked this pull request as ready for review
July 3, 2026 20:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #170 asks how to configure Morphik with a LiteLLM proxy or another OpenAI-compatible endpoint. Morphik already reads model definitions from
[registered_models]and usesapi_basefor LiteLLM/OpenAI-compatible model definitions, but the Docker guide and sample configs did not show that setup clearly.This PR documents the supported
registered_models.<key>.api_basepath and updates the Docker guide example to match the current backend configuration shape.Changes
morphik.tomlandmorphik.docker.toml.[completion].modeland[embedding].modelso the sample config path is end to end.[registered_models]keys referenced from[completion]and[embedding].api_base.morphikandworker.api_base, whilebase_urlandbaseUrlexamples belong to separate UI/API surfaces.customin Morphik metadata/provider fields even though runtime calls still use the configured model and endpoint.host-gatewaysetups on every proxy-calling container, includingmorphikandworker.LITELLM_DUMMY_API_KEY, real proxy credentials should not be placed inregistered_models.*.api_keybecause registered-model config can appear in logs and model metadata responses, credentials should not be embedded inapi_base/base_url/baseUrlURLs, dummy values do not secure unauthenticated local proxies, and remote proxy endpoints should use HTTPS.[completion].modelcovers query and agent traffic, while contextual chunking and parser vision model selectors should be updated separately if those flows should also use the proxy.morphikandworkerafter config/env changes, with a log-based smoke check for the selected proxy model keys after exercising query and ingestion traffic.Why this matters
Self-hosted users can configure an OpenAI-compatible proxy without code changes, but they need to put the endpoint on the registered model entry used for LiteLLM-backed calls. The docs now show that path directly and avoid the older
base_urlexample shape that does not match the backend model registry.Tests
Commands run:
.venv/bin/python -c 'import tomli, pathlib; [tomli.loads(pathlib.Path(p).read_text()) for p in ("morphik.toml", "morphik.docker.toml")]; print("toml parse passed")'— passed..venv/bin/pythonextraction/parse of alltomlcode fences inDOCKER.md— passed; 2 snippets parsed..venv/bin/pythonextraction/parse of allyamlcode fences inDOCKER.md— passed; 2 snippets parsed..venv/bin/pythonextraction plusbash -nsyntax check for allbashcode fences inDOCKER.md— passed; 8 snippets checked..venv/bin/pythonparse of the commentedlitellm_proxy_chat/litellm_proxy_embeddingexamples, plus selector-hint, expected proxy endpoint, dimension-warning, anddocument_analysisexclusion checks — passed; 2 entries in each sample config parsed..venv/bin/pythonstructured assertions for exact proxy docs snippets covering same-Compose endpoint, custom-config worker mount, service recreation command, traffic-gated log smoke check, selector hints, embedding-dimension warning, log/metadata-exposure warning, credential-bearing URL warning, shared-service env wording,.envsecrecy wording, and extra-selector scope — passed.if rg -n 'api_key = "YOUR_PROXY_API_KEY"|api_key = "dummy"|Omit `api_key`|omit `api_key`|host\\.docker\\.internal:4000", api_key|litellm_proxy_(chat|embedding).*host\\.docker\\.internal:4000|base_url = "http://ollama:11434"|provider = "ollama"|model_name = "llama3\\.2"|The default `morphik\\.toml` is configured for Docker|Only if using OpenAI|Ollama completion models|Do not use `base_url`|OPENAI_API_KEY=sk-\\.\\.\\.|<openai-or-proxy-key>|in the Morphik environment|Do not add proxy credentials|Do not commit real proxy credentials in api_key fields|may appear as `custom`|Restart Morphik|other model selector settings|contextual chunking, agent, query|document analysis, or parser vision|\\[document_analysis\\]\\.model' DOCKER.md morphik.toml morphik.docker.toml -S; then echo 'stale or unsafe proxy docs pattern remains'; exit 1; else echo 'no stale or unsafe proxy docs patterns found'; fi— passed.rg -n 'A Dockermorphik\.tomlcan configure local Ollama models|proxy-backed LiteLLM/OpenAI-compatible|docker compose up -d --force-recreate morphik worker|After running one query and one small ingestion|safe only when secrets are not embedded|grep -E "litellm_proxy_\\(chat\\|embedding\\)"|/api-keysacceptsbase_url|stores/returns it asbaseUrl|classified ascustom|OpenAI-compatible proxies|client-compatibility placeholder|LITELLM_DUMMY_API_KEY|registered_models\.\*\.api_key|application or worker logs and model metadata responses|credentials or bearer tokens|baseUrlURLs|parser\\.contextual_chunking_model|\\[parser\\.vision\\]\\.model|Keep dimensions compatible with existing vectors|does not rewrite existing pgvector data|my-custom-morphik\\.toml:/app/morphik\\.toml|OPENAI_API_KEY=your-openai-or-proxy-key|Keep\.envlocal|LiteLLM proxy example: model|litellm_proxy_chat|litellm_proxy_embedding|OPENAI_API_KEY|dummy|proxy-calling service|host-gateway|worker|morphik|general LiteLLM|HTTPS|api_base|your-openai-or-proxy-key' DOCKER.md morphik.toml morphik.docker.toml -S— passed.rg -n 'for key, value in (config|self\\.model_config)\\.items\\(\\)|model_params\\[key\\] = value|litellm\\.a(completion|embedding)\\(|api_base|_extract_provider|LITELLM_DUMMY_API_KEY|host\\.docker\\.internal|ingestion_worker|embedding_model|logger\\.(info|debug).*model_config|model config|baseUrl|model_config|DOCUMENT_ANALYSIS_MODEL|contextual_chunking_model|VideoParser' core/completion/litellm_completion.py core/embedding/litellm_embedding.py core/parser/morphik_parser.py core/parser/video/parse_video.py core/api.py core/config.py core/workers/ingestion_worker.py core/services_init.py core/routes/models.py -S— passed; confirmed registered-model passthrough, local embedding key handling, provider-labeling paths, worker/service embedding usage, registered-model config logging/metadata surfaces, and selector-consumer boundaries.git diff --check origin/main...HEAD— passed.Also attempted:
pythonTOML parse command — not run becausepythonis unavailable on PATH.python3TOML parse command — not run because this system Python lackstomllib.Risk
Risk level: low
This is a docs/comment-only change. It does not change runtime defaults, model resolution, LiteLLM parameters, or Docker behavior. The main risk is example accuracy: the examples intentionally use
api_basebecause that is the registered-model key the current backend expects for LiteLLM/OpenAI-compatible proxy model definitions. The docs now call out that embedding model or dimension changes on existing deployments require compatible existing vectors or a data migration/re-ingestion plan.Issue
Fixes #170.
Notes for maintainers
This PR does not add
base_urlalias support forregistered_models. If maintainers want that, it should be a separate code change with completion and embedding tests.