litellm/llms/openai_like/README.md
This directory contains the new JSON-based configuration system for OpenAI-compatible providers.
Instead of creating a full Python module for simple OpenAI-compatible providers, you can now define them in a single JSON file.
providers.json - Configuration file for all JSON-based providersjson_loader.py - Loads and parses the JSON configurationdynamic_config.py - Generates Python config classes from JSON (chat + responses)chat/ - OpenAI-like chat completion handlersresponses/ - OpenAI-like Responses API handlersEdit providers.json and add your provider:
{
"your_provider": {
"base_url": "https://api.yourprovider.com/v1",
"api_key_env": "YOUR_PROVIDER_API_KEY"
}
}
That's it! The provider will be automatically loaded and available.
{
"your_provider": {
"base_url": "https://api.yourprovider.com/v1",
"api_key_env": "YOUR_PROVIDER_API_KEY",
// Optional: Override base_url via environment variable
"api_base_env": "YOUR_PROVIDER_API_BASE",
// Optional: Which base class to use (default: "openai_gpt")
"base_class": "openai_gpt", // or "openai_like"
// Optional: Parameter name mappings
"param_mappings": {
"max_completion_tokens": "max_tokens"
},
// Optional: Parameter constraints
"constraints": {
"temperature_max": 1.0,
"temperature_min": 0.0,
"temperature_min_with_n_gt_1": 0.3
},
// Optional: Special handling flags
"special_handling": {
"convert_content_list_to_string": true
}
}
}
The first JSON-configured provider:
{
"publicai": {
"base_url": "https://api.publicai.co/v1",
"api_key_env": "PUBLICAI_API_KEY",
"api_base_env": "PUBLICAI_API_BASE",
"base_class": "openai_gpt",
"param_mappings": {
"max_completion_tokens": "max_tokens"
},
"special_handling": {
"convert_content_list_to_string": true
}
}
}
import litellm
response = litellm.completion(
model="publicai/swiss-ai/apertus-8b-instruct",
messages=[{"role": "user", "content": "Hello"}],
)
Providers that support the OpenAI Responses API (/v1/responses) can declare it via supported_endpoints:
{
"your_provider": {
"base_url": "https://api.yourprovider.com/v1",
"api_key_env": "YOUR_PROVIDER_API_KEY",
"supported_endpoints": ["/v1/chat/completions", "/v1/responses"]
}
}
This enables litellm.responses(model="your_provider/model-name", ...) with zero Python code.
The provider inherits all request/response handling from OpenAI's Responses API config.
If supported_endpoints is omitted, it defaults to [] (only chat completions, which is always enabled for JSON providers).
json_loader.py checks supported_endpoints for /v1/responsesdynamic_config.py generates a responses config class (inherits from OpenAIResponsesAPIConfig)ProviderConfigManager.get_provider_responses_api_config() returns the generated configUse a Python config class if you need:
For providers that are mostly OpenAI-compatible but need small overrides (e.g. preset model handling),
you can inherit from OpenAIResponsesAPIConfig and override only what's needed — see
litellm/llms/perplexity/responses/transformation.py for a minimal example (~40 lines).
json_loader.py loads providers.json on importdynamic_config.py generates config classes on-demandThe JSON system is integrated at:
litellm/litellm_core_utils/get_llm_provider_logic.py - Provider resolutionlitellm/utils.py - ProviderConfigManager (chat + responses)litellm/responses/main.py - Responses API routinglitellm/constants.py - openai_compatible_providers list