feat(charity_engine): add Charity Engine provider - #23223
Conversation
Charity Engine is a crowdsourced distributed computing platform that donates processing power to charitable causes. Its inference API provides OpenAI-compatible chat, completions, and embeddings endpoints.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR registers Charity Engine as a new JSON-backed OpenAI-compatible provider by adding its entry to Key changes:
All three files follow established patterns and are additive-only. Confidence Score: 5/5
Sequence DiagramsequenceDiagram
participant User
participant litellm
participant get_llm_provider
participant JSONProviderRegistry
participant JSONProviderConfig
participant CharityEngineAPI
User->>litellm: completion("charity_engine/gemma3:270m", ...)
litellm->>get_llm_provider: model="charity_engine/gemma3:270m"
get_llm_provider->>JSONProviderRegistry: exists("charity_engine")
JSONProviderRegistry-->>get_llm_provider: true
get_llm_provider->>JSONProviderRegistry: get("charity_engine")
JSONProviderRegistry-->>get_llm_provider: SimpleProviderConfig(base_url, api_key_env, param_mappings)
get_llm_provider->>JSONProviderConfig: _get_openai_compatible_provider_info()
JSONProviderConfig-->>get_llm_provider: resolved base_url and api_key from env
get_llm_provider-->>litellm: ("gemma3:270m", "charity_engine", resolved_key, base_url)
litellm->>JSONProviderConfig: get_complete_url(api_base)
JSONProviderConfig-->>litellm: base_url + "/chat/completions"
litellm->>JSONProviderConfig: map_openai_params(max_completion_tokens → max_tokens)
litellm->>CharityEngineAPI: POST /remotejobs/v2/inference/chat/completions
CharityEngineAPI-->>litellm: OpenAI-compatible response
litellm-->>User: ModelResponse
Last reviewed commit: 6721c20 |
| "charity_engine": { | ||
| "base_url": "https://api.charityengine.services/remotejobs/v2/inference/", | ||
| "api_key_env": "CHARITY_ENGINE_API_KEY", | ||
| "api_base_env": "CHARITY_ENGINE_API_BASE", | ||
| "param_mappings": { | ||
| "max_completion_tokens": "max_tokens" | ||
| } | ||
| } |
There was a problem hiding this comment.
The PR submission checklist explicitly requires at least one test to be added for new providers (see the contributing guide and other providers like xiaomi_mimo which have a dedicated test file). No test file (e.g., tests/test_litellm/llms/openai_like/test_charity_engine.py) was added in this PR, which means the provider registration, config loading, and provider resolution are untested.
Following the pattern established by test_xiaomi_mimo.py and test_assemblyai_provider.py, a test should at minimum verify:
JSONProviderRegistry.exists("charity_engine")isTrue- The loaded config has the expected
base_url,api_key_env,api_base_env, andparam_mappings - Provider resolution routes
charity_engine/<model>correctly
Verify JSONProviderRegistry config, provider list membership, model routing for charity_engine/<model>, and Router compatibility.
| "charity_engine": { | ||
| "base_url": "https://api.charityengine.services/remotejobs/v2/inference/", | ||
| "api_key_env": "CHARITY_ENGINE_API_KEY", | ||
| "api_base_env": "CHARITY_ENGINE_API_BASE", | ||
| "param_mappings": { | ||
| "max_completion_tokens": "max_tokens" | ||
| } | ||
| } |
There was a problem hiding this comment.
The charity_engine provider is registered in providers.json, but the corresponding CHARITY_ENGINE = "charity_engine" enum entry is missing from LlmProviders in litellm/types/utils.py.
This causes two concrete test failures:
- Line 27 of test_charity_engine.py will fail with
AttributeError: The test assertshasattr(LlmProviders, "CHARITY_ENGINE"), which will raise an error because the enum member does not exist. - Line 29 of test_charity_engine.py will fail: The test asserts
"charity_engine" in litellm.provider_list, butprovider_listis built fromlist(LlmProviders)inlitellm/__init__.py(line 1752), so the provider will be absent.
Every other JSON-backed provider in this pattern added the enum entry — for example XIAOMI_MIMO = "xiaomi_mimo" (line 3212), ASSEMBLYAI = "assemblyai" (line 3179), and SYNTHETIC = "synthetic" (line 3207) in litellm/types/utils.py.
Fix: Add the following line to class LlmProviders in litellm/types/utils.py:
CHARITY_ENGINE = "charity_engine"Enables provider_list membership and LlmProviders.CHARITY_ENGINE resolution required by the provider and test suite.
| def test_charity_engine_provider_resolution(self): | ||
| """Test that provider resolution finds charity_engine""" | ||
| from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider | ||
|
|
||
| model, provider, api_key, api_base = get_llm_provider( | ||
| model="charity_engine/gemma3:270m", | ||
| custom_llm_provider=None, | ||
| api_base=None, | ||
| api_key=None, | ||
| ) | ||
|
|
||
| assert model == "gemma3:270m" | ||
| assert provider == "charity_engine" | ||
| assert api_base == "https://api.charityengine.services/remotejobs/v2/inference/" |
There was a problem hiding this comment.
Test non-deterministic when API base env var is set
charity_engine is the only provider in this test suite that declares an api_base_env override in providers.json. The _get_openai_compatible_provider_info method in dynamic_config.py resolves the base URL with this priority:
if not resolved_base and provider.api_base_env:
resolved_base = get_secret_str(provider.api_base_env) # reads env var first
if not resolved_base:
resolved_base = provider.base_url # fallback defaultIf the environment variable for the API base is present in the runner's environment (e.g., a developer who has tested against a self-hosted instance), get_llm_provider returns the env var value instead of the default base_url, causing the assertion on line 57 to fail. The analogous test_xiaomi_mimo_provider_resolution is unaffected because xiaomi_mimo does not define api_base_env.
Fix: pop the env var inside the test using mock.patch.dict before calling get_llm_provider, so the assertion always tests against the static default URL regardless of what is configured in the environment.
The CHARITY_ENGINE_API_BASE env var could override the base_url in CI, causing test_charity_engine_provider_resolution to fail intermittently.
| "api_key_env": "ASSEMBLYAI_API_KEY" | ||
| }, | ||
| "charity_engine": { | ||
| "base_url": "https://api.charityengine.services/remotejobs/v2/inference/", |
There was a problem hiding this comment.
Trailing slash in base_url produces double-slash endpoint
The base_url value ends with /. In dynamic_config.py (line 94-95), the get_complete_url method constructs the final endpoint like this:
if not api_base.endswith("/chat/completions"):
api_base = f"{api_base}/chat/completions"Because the value ends with / (not /chat/completions), the constructed URL becomes:
https://api.charityengine.services/remotejobs/v2/inference//chat/completions
The double slash // in the path could cause routing issues on strict server implementations, even though most servers normalize it. The same pattern exists in the chutes entry and may work in practice, but it is cleaner to remove the trailing slash to match the majority of providers:
| "base_url": "https://api.charityengine.services/remotejobs/v2/inference/", | |
| "base_url": "https://api.charityengine.services/remotejobs/v2/inference", |
The corresponding assertion in test_charity_engine_provider_resolution (line 56) would also need updating to match.
* feat(charity_engine): add Charity Engine provider Charity Engine is a crowdsourced distributed computing platform that donates processing power to charitable causes. Its inference API provides OpenAI-compatible chat, completions, and embeddings endpoints. * test(charity_engine): add provider config and resolution tests Verify JSONProviderRegistry config, provider list membership, model routing for charity_engine/<model>, and Router compatibility. * feat(charity_engine): add Charity Engine to LlmProviders enum Enables provider_list membership and LlmProviders.CHARITY_ENGINE resolution required by the provider and test suite. * fix(charity_engine): remove api_base_env to fix non-deterministic test The CHARITY_ENGINE_API_BASE env var could override the base_url in CI, causing test_charity_engine_provider_resolution to fail intermittently. * fix(charity_engine): remove trailing slash from base_url
Charity Engine is a crowdsourced distributed computing platform that donates processing power to charitable causes. Its inference API provides OpenAI-compatible chat, completions, and embeddings endpoints.
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
Changes
Add Charity Engine to the list of openai_like providers.