The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat(cognition): give Cognition its own provider identity
mateo-berrie00301703f2f
diff --git a/README.md b/README.mdindex 32b0160dbaa..247e072f3a7 100644--- a/README.md+++ b/README.md@@ -292,6 +292,7 @@ curl -X POST 'http://0.0.0.0:4000/v1/chat/completions' \| [Clarifai (`clarifai`)](https://docs.litellm.ai/docs/providers/clarifai) | ✅ | ✅ | ✅ | | | | | | | || [Cloudflare AI Workers (`cloudflare`)](https://docs.litellm.ai/docs/providers/cloudflare_workers) | ✅ | ✅ | ✅ | | | | | | | || [Codestral (`codestral`)](https://docs.litellm.ai/docs/providers/codestral) | ✅ | ✅ | ✅ | | | | | | | |+| [Cognition (`cognition`)](https://docs.litellm.ai/docs/providers/cognition) | ✅ | ✅ | | | | | | | | || [Cohere (`cohere`)](https://docs.litellm.ai/docs/providers/cohere) | ✅ | ✅ | ✅ | ✅ | | | | | | ✅ || [Cohere Chat (`cohere_chat`)](https://docs.litellm.ai/docs/providers/cohere) | ✅ | ✅ | ✅ | | | | | | | || [CometAPI (`cometapi`)](https://docs.litellm.ai/docs/providers/cometapi) | ✅ | ✅ | ✅ | ✅ | | | | | | |diff --git a/litellm/constants.py b/litellm/constants.pyindex a845b1a49ae..ccbeb260a83 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -763,6 +763,7 @@ openai_compatible_endpoints: Final[list] = ["https://api.libertai.io/v1","https://pinstripes.io/v1","https://api.meta.ai/v1",+ "https://api.cognition.ai/v1",]@@ -830,6 +831,7 @@ openai_compatible_providers: Final[list] = ["pinstripes", # Pinstripes - JSON-configured provider"darkbloom","meta", # Meta Model API (Muse Spark) - JSON-configured provider+ "cognition", # Cognition - JSON-configured provider]openai_text_completion_compatible_providers: Final[list] = [ # providers that support `/v1/completions`"together_ai",diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.pyindex dbb40913e14..e674fc37673 100644--- a/litellm/litellm_core_utils/get_llm_provider_logic.py+++ b/litellm/litellm_core_utils/get_llm_provider_logic.py@@ -349,6 +349,9 @@ def get_llm_provider(elif endpoint == "https://api.meta.ai/v1":custom_llm_provider = "meta"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)if api_base is not None and not isinstance(api_base, str):raise Exception(f"api base needs to be a string. api_base={api_base}")diff --git a/litellm/llms/openai_like/json_loader.py b/litellm/llms/openai_like/json_loader.pyindex 38f3866cfc3..5cdaff90d24 100644--- a/litellm/llms/openai_like/json_loader.py+++ b/litellm/llms/openai_like/json_loader.py@@ -65,6 +65,11 @@ class JSONProviderRegistry:"""Check if a provider is defined via JSON"""return slug in cls._providers+ @classmethod+ def get_by_base_url(cls, base_url: str) -> SimpleProviderConfig | None:+ """Get a provider configuration by its default base url"""+ return next((provider for provider in cls._providers.values() if provider.base_url == base_url), None)+@classmethoddef supports_responses_api(cls, slug: str) -> bool:"""Check if a JSON provider supports the Responses API"""diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.jsonindex 164100d4194..5f57aaa78d8 100644--- a/litellm/llms/openai_like/providers.json+++ b/litellm/llms/openai_like/providers.json@@ -175,6 +175,11 @@"base_class": "openai_gpt","supported_endpoints": ["/v1/chat/completions", "/v1/responses", "/v1/messages"]},+ "cognition": {+ "base_url": "https://api.cognition.ai/v1",+ "api_key_env": "COGNITION_API_KEY",+ "api_base_env": "COGNITION_API_BASE"+ },"pinstripes": {"base_url": "https://pinstripes.io/v1","api_key_env": "PINSTRIPES_API_KEY",diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex b9c8824aa67..5d859a05963 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -48475,6 +48475,26 @@"supports_reasoning": true,"supports_vision": false},+ "cognition/swe-1.6": {+ "input_cost_per_token": 5e-07,+ "output_cost_per_token": 2.5e-06,+ "cache_read_input_token_cost": 2e-07,+ "litellm_provider": "cognition",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_prompt_caching": true,+ "source": "https://docs.devin.ai/windsurf/plugins/cascade/models"+ },+ "cognition/swe-1.7": {+ "input_cost_per_token": 2.5e-06,+ "output_cost_per_token": 1.25e-05,+ "cache_read_input_token_cost": 1e-06,+ "litellm_provider": "cognition",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_prompt_caching": true,+ "source": "https://docs.devin.ai/windsurf/plugins/cascade/models"+ },"pinstripes/ps/glm-4.5-air": {"max_tokens": 128000,"max_input_tokens": 128000,diff --git a/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.jsonindex dd7712aabca..d47d74ead28 100644--- a/litellm/provider_endpoints_support_backup.json+++ b/litellm/provider_endpoints_support_backup.json@@ -528,6 +528,23 @@"interactions": true}},+ "cognition": {+ "display_name": "Cognition (`cognition`)",+ "url": "https://docs.litellm.ai/docs/providers/cognition",+ "endpoints": {+ "chat_completions": true,+ "messages": true,+ "responses": false,+ "embeddings": false,+ "image_generations": false,+ "audio_transcriptions": false,+ "audio_speech": false,+ "moderations": false,+ "batches": false,+ "rerank": false,+ "a2a": false+ }+ },"cohere": {"display_name": "Cohere (`cohere`)","url": "https://docs.litellm.ai/docs/providers/cohere",diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.jsonindex ab13773614a..9c2e94dd861 100644--- a/litellm/proxy/public_endpoints/provider_create_fields.json+++ b/litellm/proxy/public_endpoints/provider_create_fields.json@@ -772,6 +772,34 @@],"default_model_placeholder": "gpt-3.5-turbo"},+ {+ "provider": "Cognition",+ "provider_display_name": "Cognition",+ "litellm_provider": "cognition",+ "credential_fields": [+ {+ "key": "api_base",+ "label": "API Base",+ "placeholder": "https://api.cognition.ai/v1",+ "tooltip": null,+ "required": false,+ "field_type": "text",+ "options": null,+ "default_value": null+ },+ {+ "key": "api_key",+ "label": "API Key",+ "placeholder": null,+ "tooltip": null,+ "required": true,+ "field_type": "password",+ "options": null,+ "default_value": null+ }+ ],+ "default_model_placeholder": "cognition/swe-1.7"+ },{"provider": "Cohere","provider_display_name": "Cohere",diff --git a/litellm/types/utils.py b/litellm/types/utils.pyindex 41210d18495..e6138101899 100644--- a/litellm/types/utils.py+++ b/litellm/types/utils.py@@ -3782,6 +3782,7 @@ class LlmProviders(str, Enum):TENSORMESH = "tensormesh"LIBERTAI = "libertai"PINSTRIPES = "pinstripes"+ COGNITION = "cognition"DARKBLOOM = "darkbloom"META = "meta"LITELLM_AGENT = "litellm_agent"diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex b9c8824aa67..5d859a05963 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -48475,6 +48475,26 @@"supports_reasoning": true,"supports_vision": false},+ "cognition/swe-1.6": {+ "input_cost_per_token": 5e-07,+ "output_cost_per_token": 2.5e-06,+ "cache_read_input_token_cost": 2e-07,+ "litellm_provider": "cognition",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_prompt_caching": true,+ "source": "https://docs.devin.ai/windsurf/plugins/cascade/models"+ },+ "cognition/swe-1.7": {+ "input_cost_per_token": 2.5e-06,+ "output_cost_per_token": 1.25e-05,+ "cache_read_input_token_cost": 1e-06,+ "litellm_provider": "cognition",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_prompt_caching": true,+ "source": "https://docs.devin.ai/windsurf/plugins/cascade/models"+ },"pinstripes/ps/glm-4.5-air": {"max_tokens": 128000,"max_input_tokens": 128000,diff --git a/provider_endpoints_support.json b/provider_endpoints_support.jsonindex ec0b1c27344..950bf61dbb7 100644--- a/provider_endpoints_support.json+++ b/provider_endpoints_support.json@@ -563,6 +563,23 @@"interactions": true}},+ "cognition": {+ "display_name": "Cognition (`cognition`)",+ "url": "https://docs.litellm.ai/docs/providers/cognition",+ "endpoints": {+ "chat_completions": true,+ "messages": true,+ "responses": false,+ "embeddings": false,+ "image_generations": false,+ "audio_transcriptions": false,+ "audio_speech": false,+ "moderations": false,+ "batches": false,+ "rerank": false,+ "a2a": false+ }+ },"cohere": {"display_name": "Cohere (`cohere`)","url": "https://docs.litellm.ai/docs/providers/cohere",diff --git a/tests/test_litellm/llms/openai_like/test_cognition_provider.py b/tests/test_litellm/llms/openai_like/test_cognition_provider.pynew file mode 100644index 00000000000..26bdfa82944--- /dev/null+++ b/tests/test_litellm/llms/openai_like/test_cognition_provider.py@@ -0,0 +1,173 @@+"""+Tests for the Cognition provider identity.++Cognition serves an OpenAI-compatible /v1/chat/completions surface, but it must resolve to its+own `cognition` provider so OpenAI-specific pricing and provider-level reporting never apply to+its traffic.+"""++import json+from pathlib import Path++import pytest++import litellm+++class TestCognitionProviderIdentity:+ def test_cognition_is_a_registered_provider(self):+ from litellm import LlmProviders++ assert LlmProviders.COGNITION.value == "cognition"+ assert "cognition" in litellm.provider_list++ def test_cognition_json_config(self):+ from litellm.llms.openai_like.json_loader import JSONProviderRegistry++ cognition = JSONProviderRegistry.get("cognition")+ assert cognition is not None+ assert cognition.base_url == "https://api.cognition.ai/v1"+ assert cognition.api_key_env == "COGNITION_API_KEY"+ assert cognition.api_base_env == "COGNITION_API_BASE"++ def test_cognition_in_openai_compatible_providers(self):+ from litellm.constants import openai_compatible_providers++ assert "cognition" in openai_compatible_providers++ def test_prefixed_model_resolves_to_cognition_not_openai(self):+ from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider++ model, provider, _, api_base = get_llm_provider(+ model="cognition/swe-1.7",+ custom_llm_provider=None,+ api_base=None,+ api_key=None,+ )++ assert model == "swe-1.7"+ assert provider == "cognition"+ assert api_base == "https://api.cognition.ai/v1"++ def test_explicit_api_base_and_key_win(self):+ from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider++ _, provider, api_key, api_base = get_llm_provider(+ model="cognition/swe-1.7",+ custom_llm_provider=None,+ api_base="https://cognition.internal.example/v1",+ api_key="sk-test",+ )++ assert provider == "cognition"+ assert api_base == "https://cognition.internal.example/v1"+ assert api_key == "sk-test"++ def test_api_base_autodetects_cognition(self, monkeypatch: pytest.MonkeyPatch):+ from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider++ monkeypatch.setenv("COGNITION_API_KEY", "sk-cognition-env")++ _, provider, api_key, api_base = get_llm_provider(+ model="swe-1.7",+ custom_llm_provider=None,+ api_base="https://api.cognition.ai/v1",+ api_key=None,+ )++ assert provider == "cognition"+ assert api_base == "https://api.cognition.ai/v1"+ assert api_key == "sk-cognition-env"++ def test_autodetected_api_base_keeps_the_caller_api_key(self, monkeypatch: pytest.MonkeyPatch):+ from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider++ monkeypatch.setenv("COGNITION_API_KEY", "sk-cognition-env")++ _, provider, api_key, _ = get_llm_provider(+ model="swe-1.7",+ custom_llm_provider=None,+ api_base="https://api.cognition.ai/v1",+ api_key="sk-cognition-caller",+ )++ assert provider == "cognition"+ assert api_key == "sk-cognition-caller"++ def test_env_api_key_is_read_from_cognition_variable(self, monkeypatch: pytest.MonkeyPatch):+ from litellm.llms.openai_like.dynamic_config import create_config_class+ from litellm.llms.openai_like.json_loader import JSONProviderRegistry++ monkeypatch.delenv("OPENAI_API_KEY", raising=False)+ monkeypatch.setenv("COGNITION_API_KEY", "sk-cognition-env")++ provider = JSONProviderRegistry.get("cognition")+ assert provider is not None++ api_base, api_key = create_config_class(provider)()._get_openai_compatible_provider_info(None, None)+ assert api_base == "https://api.cognition.ai/v1"+ assert api_key == "sk-cognition-env"+++class TestCognitionCostTracking:+ @pytest.mark.parametrize(+ "model, input_cost, output_cost",+ [+ ("cognition/swe-1.6", 5e-07, 2.5e-06),+ ("cognition/swe-1.7", 2.5e-06, 1.25e-05),+ ],+ )+ def test_cost_map_entries(self, model: str, input_cost: float, output_cost: float):+ info = litellm.get_model_info(model=model)++ assert info["litellm_provider"] == "cognition"+ assert info["mode"] == "chat"+ assert info["input_cost_per_token"] == input_cost+ assert info["output_cost_per_token"] == output_cost++ def test_cost_differs_from_openai_pricing(self):+ """A cognition-prefixed model must never be priced off an OpenAI cost entry."""+ from litellm.cost_calculator import cost_per_token++ prompt_cost, completion_cost = cost_per_token(+ model="cognition/swe-1.7",+ prompt_tokens=1_000_000,+ completion_tokens=1_000_000,+ custom_llm_provider="cognition",+ )++ assert prompt_cost == pytest.approx(2.5)+ assert completion_cost == pytest.approx(12.5)++ def test_supported_endpoints_matrix(self):+ matrix = json.loads((Path(litellm.__file__).parent / "provider_endpoints_support_backup.json").read_text())++ endpoints = matrix["providers"]["cognition"]["endpoints"]+ assert endpoints["chat_completions"] is True+ assert endpoints["embeddings"] is False+++class TestCognitionRouting:+ @pytest.mark.asyncio+ async def test_router_spend_is_attributed_to_cognition_pricing(self):+ """Routed traffic is costed off the cognition entry, not an OpenAI one."""+ from litellm import Router++ router = Router(+ model_list=[+ {+ "model_name": "swe",+ "litellm_params": {"model": "cognition/swe-1.7", "api_key": "sk-test"},+ }+ ]+ )++ response = await router.acompletion(+ model="swe",+ messages=[{"role": "user", "content": "hi"}],+ mock_response="hello from swe",+ )++ usage = response.usage+ expected = usage.prompt_tokens * 2.5e-06 + usage.completion_tokens * 1.25e-05+ assert response._hidden_params["response_cost"] == pytest.approx(expected)diff --git a/tests/test_litellm/proxy/public_endpoints/test_public_endpoints.py b/tests/test_litellm/proxy/public_endpoints/test_public_endpoints.pyindex 03d228cc732..72e7b1c18d6 100644--- a/tests/test_litellm/proxy/public_endpoints/test_public_endpoints.py+++ b/tests/test_litellm/proxy/public_endpoints/test_public_endpoints.py@@ -298,6 +298,37 @@ def test_nvidia_riva_provider_fields():assert fields_by_key["nvcf_function_id"]["required"] is False+def test_cognition_provider_fields():+ """Cognition must be selectable in the Add Model flow (LIT-5348).++ The dropdown is driven entirely by /public/providers/fields, so without an+ entry here admins have to fall back to the generic OpenAI-compatible route,+ which is exactly the provider identity mix-up this feature removes.+ """+ app_instance = FastAPI()+ app_instance.include_router(router)+ test_client = TestClient(app_instance)++ response = test_client.get("/public/providers/fields")+ assert response.status_code == 200+ providers = response.json()++ cognition = next((p for p in providers if p["provider"] == "Cognition"), None)+ assert cognition is not None, "Cognition provider entry not found"++ assert cognition["provider_display_name"] == "Cognition"+ assert cognition["litellm_provider"] == "cognition"+ assert cognition["default_model_placeholder"].startswith("cognition/")++ fields_by_key = {f["key"]: f for f in cognition["credential_fields"]}++ assert fields_by_key["api_key"]["required"] is True+ assert fields_by_key["api_key"]["field_type"] == "password"++ assert fields_by_key["api_base"]["field_type"] == "text"+ assert fields_by_key["api_base"]["required"] is False++def test_google_ai_studio_provider_fields_expose_api_base():"""The Google AI Studio (gemini) credential form must let admins set a customapi_base so they can point at a Gemini-compatible gateway (e.g. a self-hosteddiff --git a/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx b/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsxindex e9bb63dd964..f2dbd866c2d 100644--- a/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx+++ b/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx@@ -137,6 +137,7 @@ describe("provider_info_helpers", () => {Providers.AUTO_ROUTER,Providers.BYTEZ,Providers.CLARIFAI,+ Providers.Cognition,Providers.COMPACTIFAI,Providers.DATAROBOT,Providers.DOCKER_MODEL_RUNNER,@@ -252,6 +253,10 @@ describe("provider_info_helpers", () => {expect(getPlaceholder("WATSONX")).toBe("watsonx/ibm/granite-3-3-8b-instruct");});+ it("should return cognition/swe-1.7 placeholder for Cognition provider", () => {+ expect(getPlaceholder(Providers.Cognition)).toBe("cognition/swe-1.7");+ });+it("should return default gpt-3.5-turbo placeholder for unknown provider", () => {expect(getPlaceholder("UnknownProvider" as any)).toBe("gpt-3.5-turbo");});diff --git a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx b/ui/litellm-dashboard/src/components/provider_info_helpers.tsxindex ad6d044eb7b..519438622f3 100644--- a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx+++ b/ui/litellm-dashboard/src/components/provider_info_helpers.tsx@@ -85,6 +85,7 @@ export enum Providers {CLARIFAI = "Clarifai",CLOUDFLARE = "Cloudflare",CODESTRAL = "Codestral",+ Cognition = "Cognition",Cohere = "Cohere",COHERE_CHAT = "Cohere Chat",COMETAPI = "Cometapi",@@ -194,6 +195,7 @@ export const provider_map: Record<string, string> = {CLARIFAI: "clarifai",CLOUDFLARE: "cloudflare",CODESTRAL: "codestral",+ Cognition: "cognition",Cohere: "cohere",COHERE_CHAT: "cohere_chat",COMETAPI: "cometapi",@@ -409,6 +411,7 @@ const providerPlaceholderMap: Partial<Record<Providers, string>> = {[Providers.Azure]: "my-deployment",[Providers.Azure_AI_Studio]: "azure_ai/command-r-plus",[Providers.Bedrock]: "claude-3-opus",+ [Providers.Cognition]: "cognition/swe-1.7",[Providers.Cursor]: "cursor/claude-4-sonnet",[Providers.DeepInfra]: "deepinfra/<any-model-on-deepinfra>",[Providers.FalAI]: "fal_ai/fal-ai/flux-pro/v1.1-ultra",