feat(cognition): add a distinct provider identity for Cognition - #36239
feat(cognition): add a distinct provider identity for Cognition#36239devin-ai-integration[bot] wants to merge 4 commits into
Conversation
Register cognition as a JSON-configured OpenAI-compatible provider so its traffic no longer rides on custom_llm_provider=openai, keeping OpenAI cost discounts and provider-level reporting out of it. Adds the SWE cost map entries, the supported-endpoints matrix row, and the Admin UI provider option. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThis PR registers Cognition as a distinct OpenAI-compatible provider across provider resolution, pricing, endpoint metadata, and the Admin UI.
Confidence Score: 3/5This PR is not safe to merge until Cognition requests can no longer inherit and disclose an unrelated OpenAI credential when Cognition credentials are absent. The new autodetection path can return no Cognition key, after which the shared OpenAI-compatible dispatcher substitutes a globally configured OpenAI key and sends it to the Cognition endpoint. Files Needing Attention: litellm/litellm_core_utils/get_llm_provider_logic.py and litellm/main.py
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/get_llm_provider_logic.py | Adds registry-based provider autodetection and explicit-key precedence, but missing Cognition credentials can still fall through to an unrelated OpenAI key. |
| litellm/llms/openai_like/json_loader.py | Adds an exact default-base-URL registry lookup used by provider autodetection. |
| litellm/llms/openai_like/providers.json | Registers Cognition's default endpoint and credential environment variables. |
| litellm/constants.py | Registers Cognition as OpenAI-compatible and adds its endpoint to the autodetection gate. |
| model_prices_and_context_window.json | Adds Cognition SWE model pricing and capability metadata. |
| litellm/proxy/public_endpoints/provider_create_fields.json | Exposes Cognition's credential and endpoint fields to provider-creation clients. |
| ui/litellm-dashboard/src/components/provider_info_helpers.tsx | Adds Cognition to the Admin UI provider mapping. |
| tests/test_litellm/llms/openai_like/test_cognition_provider.py | Covers provider identity, default autodetection, explicit endpoint and key precedence, pricing, and routing. |
Reviews (3): Last reviewed commit: "fix(cognition): keep the caller api key ..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The dropdown is driven by /public/providers/fields, so the provider needed an entry in provider_create_fields.json. Also document COGNITION_API_KEY/COGNITION_API_BASE (docs repo PR) and regenerate the dashboard API types, which had drifted on the base branch. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptile review again |
…vider Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptile review again |
| dynamic_api_key = get_secret_str("META_API_KEY") | ||
| elif (json_provider := JSONProviderRegistry.get_by_base_url(endpoint)) is not None: | ||
| custom_llm_provider = json_provider.slug | ||
| dynamic_api_key = api_key if api_key is not None else get_secret_str(json_provider.api_key_env) |
There was a problem hiding this comment.
OpenAI credential leaks to Cognition
If Cognition is autodetected while neither an explicit api_key nor COGNITION_API_KEY is configured, this returns no key and the shared OpenAI-compatible dispatch substitutes litellm.api_key, litellm.openai_key, or OPENAI_API_KEY, sending an unrelated credential to Cognition and failing authentication.
How this was verified: The changed resolver returns None in this state, and the reached dispatch explicitly falls back through the global OpenAI credential chain.
Knowledge Base Used: LLM Provider Adapters
There was a problem hiding this comment.
That OpenAI key fallback in main.py:6163 predates this PR and hits every provider here (mistral, meta) with an unset env var, so fixing it belongs in its own change, not this one
There was a problem hiding this comment.
That's a fair point. Looking at the existing branches in the same block, they all do the same thing — dynamic_api_key = get_secret_str("SOME_API_KEY") without preserving an explicit api_key. The new JSON registry branch is actually strictly better than the precedent: it checks api_key if api_key is not None else get_secret_str(...), so it preserves an explicitly-passed key rather than overwriting it. The downstream OpenAI credential fallback when dynamic_api_key is None is pre-existing behavior shared across all providers here (mistral, meta, perplexity, etc.), not something this PR introduces or worsens. The concern doesn't apply to this change.
TLDR
Problem this solves:
custom_llm_provider: openaiHow it solves it:
cognitionin the JSON provider registryUser Flow
Before: an admin onboarding Cognition has to disguise it as OpenAI, and every report then reads Cognition spend as OpenAI spend.
openai"model": "swe-1.7"and get a normal completion backopenai, priced off whateverswe-1.7resolves to on the OpenAI side, and any OpenAI-specific discount they configured applies to itAfter: Cognition is a first-class provider, so the same deployment reports and prices as Cognition.
cognition/swe-1.5,cognition/swe-1.6andcognition/swe-1.7; they pick one, paste the key, and save"model": "swe-1.7"and get the same completion backcognition, priced from the Cognition rates ($2.50 / $12.50 per million tokens for swe-1.7), with no OpenAI discount appliedRelevant issues
Docs live in a separate repo, so the provider page and the
COGNITION_API_KEY/COGNITION_API_BASEreference rows are in BerriAI/litellm-docs#822. Thedocumentationandcode-qualitychecks here check out litellm-docsmainand fail any env var read underlitellm/that is documented nowhere, so they stay red until that PR merges.Linear ticket
Resolves LIT-5348
Pre-Submission checklist
Screenshots / Proof of Fix
Proof captured against a live proxy is in the session thread, including the Admin UI add-model flow and a real (non-mocked, paid) chat completion routed through the new provider identity. Cognition itself does not publish a public inference API, so the live call used a Cognition deployment whose
api_basepoints at a real OpenAI-compatible upstream, which is exactly how the customer's endpoint is wired.Type
🆕 New Feature
Changes
litellm/llms/openai_like/providers.jsongainsand
cognitionis registered inLlmProvidersplusopenai_compatible_providers, somodel: cognition/swe-1.7resolves to providercognitionwith the Cognition base URL and key.api_baseautodetection inget_llm_providergets no Cognition specific branch. Instead the chain ends with a registry lookup, so any provider whose default endpoint is inproviders.jsonresolves from there rather than from a hardcoded slug and key env repeated in the core util:The env key is a fallback rather than an override, so an explicit per call key survives autodetection instead of being replaced by whatever the environment holds, which is what the hardcoded branches above do today.
It sits last, so every existing hardcoded branch still wins, and JSON providers that were listed as compatible endpoints without a branch (tensormesh and libertai among them) now resolve instead of falling through with no provider.
The Add Model dropdown reads
/public/providers/fields, which just serveslitellm/proxy/public_endpoints/provider_create_fields.json, so Cognition also gets an entry there (requiredapi_key, optionalapi_base) alongside theProvidersenum andprovider_mapadditions; without it the provider is registered but unselectable in the UI.Cost map (both the root map and the bundled backup) gets
cognition/swe-1.5,cognition/swe-1.6andcognition/swe-1.7, priced from Cognition's published per-token rates, so spend is computed from the Cognition entry instead of an OpenAI one.provider_endpoints_support.json(plus backup) and the README provider table list the new provider as chat completions and messages only, since Cognition documents no Responses API, and the Admin UI provider dropdown gets a Cognition option that maps to thecognitionslug.ui/litellm-dashboard/src/lib/http/schema.d.tsis regenerated in one commit: it had drifted on the base branch (a missingtier_turnsfield on an auto-router response model), and the sync check fails on any PR until someone regenerates it. Nothing in this PR touches that model.Two notes for reviewers, both flagged on the ticket: the default
base_urlis Cognition's documented API host and can be overridden per deployment or withCOGNITION_API_BASE, and the SWE entries carry no context-window numbers because Cognition has not published them.Link to Devin session: https://app.devin.ai/sessions/c27f086d609843cdb6380708ecd31b2f
Requested by: @shivamrawat1