Skip to content

feat(providers): add Kyma API as a JSON-configured OpenAI-compatible provider - #39799

Closed
sonpiaz wants to merge 4 commits into
BerriAI:mainfrom
kyma-api:feature/add-kyma-provider
Closed

sonpiaz wants to merge 4 commits into
BerriAI:mainfrom
kyma-api:feature/add-kyma-provider

Conversation

@sonpiaz

@sonpiaz sonpiaz commented Sep 4, 2026

Copy link
Copy Markdown

What

Adds Kyma API (https://kymaapi.com) as a JSON-configured OpenAI-compatible provider, following
the darkbloom/libertai/scx-ai pattern: a providers.json entry, an LlmProviders enum value,
the two openai_compatible_* lists in constants.py, and 70 kyma/* price entries in
model_prices_and_context_window.json (root + the litellm/ backup copy). No provider-specific
Python — Kyma is a plain OpenAI-compatible /v1/chat/completions endpoint.

import litellm
response = litellm.completion(model="kyma/deepseek-v3", messages=[...])

Why

Kyma publishes measured per-model uptime (kymaapi.com/status) and public usage rankings
(kymaapi.com/rankings); its price catalog is machine-generated from the same source that serves
/v1/models, and we keep it current the same way. Six frameworks that read LiteLLM's own
cost/capability map for their own model resolution — CrewAI, LlamaIndex, the OpenAI Agents SDK's
Python bindings, DSPy, smolagents, Google ADK — pick this provider up for free once merged.

Notes for reviewers

  • Diff is addition-only (992 insertions / 0 deletions per JSON file) — this never rewrites the
    shared price file, unlike a previous attempt at this PR.
  • Two fixes applied against our own source catalog while assembling this: rounded
    floating-point noise on 27 of the 70 entries' price fields, and added
    cache_read_input_token_cost (10% of input price, our documented cache-read discount) to
    every entry with supports_prompt_caching: true — it was missing, which would have priced
    cache reads at $0 under this repo's own cost calculator.
  • provider_endpoints_support.json only claims chat_completions: true. Kyma's own API also
    serves /v1/messages, /v1/embeddings and /v1/rerank, but the JSON-configured-provider
    path only wires chat routing, so those are left false rather than overclaimed (matches the
    libertai/scx-ai precedent).

Test

tests/test_litellm/llms/openai_like/test_kyma_provider.py, 15 cases, mocked only. Uses
LiteLLM's own mock_response completion path for the routing/cost assertions — not
unittest.mock.patch on an internal — so there's no risk of a silently-skipped mock: a previous
submission patched litellm.main.completion, which is never invoked because litellm.completion
is bound at import time via from .main import *.

Verified locally against origin/litellm_internal_staging: pytest tests/test_litellm/llms/openai_like/test_kyma_provider.py (15 passed), ruff check + ruff format --check, scripts/test_quality_gate.py, scripts/type_check_gate.py,
scripts/type_discipline_gate.py, check-import-safety, check-circular-imports — all green.

Maintenance

We keep this entry current when Kyma's catalog changes. Contact hello@kymaapi.com.

Happy to adjust naming, ordering or fields to match your conventions.

…provider

Registers kyma (https://kymaapi.com) the same way as the recent darkbloom,
libertai and scx-ai providers: a providers.json entry, an LlmProviders enum
value, and the two openai_compatible_* lists in constants.py. No Python
handler code -- Kyma is a plain OpenAI-compatible /v1/chat/completions
endpoint, so the JSON-configured-provider path covers it.

Adds all 70 kyma/* entries to model_prices_and_context_window.json (root
and the litellm/ backup copy), splicing them in rather than reserializing
the file -- the prior submission (BerriAI#25543, closed) rewrote the entire 1.6MB
file (+38274/-38128), which is a guaranteed merge conflict on a
fast-moving file. This diff is addition-only.

Two fixes applied against the source catalog while assembling this:
- 27 of the 70 entries carried floating-point noise on their price fields
  (e.g. 4.9799999999999996e-08) from upstream markup math; rounded to 6
  significant figures.
- Models with supports_prompt_caching=true had no cache_read_input_token_cost,
  so LiteLLM's own cost calculator would have priced cache reads at $0.
  Kyma's documented policy is a 90% discount (10% of input price); added
  that rate to all such entries.

Adds a provider_endpoints_support.json entry (root + backup) advertising
chat_completions only -- the JSON-configured-provider path wires chat
routing alone (see the libertai/scx-ai precedent), so Kyma's own
/v1/messages, /v1/embeddings and /v1/rerank surfaces are not claimed here
even though they exist on kymaapi.com itself.

Test: tests/test_litellm/llms/openai_like/test_kyma_provider.py, 15 cases,
mocked only. Routing/cost assertions use litellm's built-in mock_response
completion path rather than patching internals -- the previous submission
patched litellm.main.completion, which is never invoked because
litellm.completion is bound at import time via `from .main import *`, so
the mock silently never fired and the "mocked" test made a real network
call.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Rok2mujdEZ2yGw8wVfbr9
@sonpiaz
sonpiaz requested a review from mateo-berri as a code owner September 4, 2026 20:16
@codspeed

codspeed Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing kyma-api:feature/add-kyma-provider (a57c09c) with litellm_internal_staging (300d335)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds Kyma as a declarative OpenAI-compatible chat provider, including routing identity, credentials, endpoint metadata, model pricing, capability data, and mocked provider tests

  • Registers the Kyma provider and default API endpoint
  • Adds 70 model catalog entries to both primary and backup maps
  • Advertises chat-completions support and adds routing, metadata, pricing, and synchronization tests
  • The test fixture leaks global model-cost state, and one model contains an unreachable pricing tier

Confidence Score: 4/5

The provider integration is mostly aligned, but the leaking test fixture and explicit source-comment rule violation should be fixed before merging

The module-scoped fixture leaves environment, model-cost, and cached model information altered for later tests, creating order-dependent suite behavior; the catalog also contains one unreachable pricing tier

Files Needing Attention: tests/test_litellm/llms/openai_like/test_kyma_provider.py, model_prices_and_context_window.json, litellm/model_prices_and_context_window_backup.json

Important Files Changed

Filename Overview
litellm/constants.py Registers Kyma's API base and provider slug in the OpenAI-compatible routing lists
litellm/llms/openai_like/providers.json Adds the declarative Kyma base URL and API-key environment variable
litellm/types/utils.py Adds Kyma to the provider enum used by provider resolution and configuration
model_prices_and_context_window.json Adds 70 Kyma pricing and capability entries, including an unreachable 256k tier for qwen-3.6-plus
litellm/model_prices_and_context_window_backup.json Mirrors the Kyma catalog and the qwen-3.6-plus tier inconsistency in the bundled backup
provider_endpoints_support.json Advertises Kyma as chat-completions-only
litellm/provider_endpoints_support_backup.json Mirrors Kyma's chat-only endpoint support in the bundled backup
tests/test_litellm/llms/openai_like/test_kyma_provider.py Adds provider, metadata, endpoint, and cost tests but leaks process-global model-cost state and contains prohibited commentary

Reviews (1): Last reviewed commit: "feat(providers): add Kyma API as a JSON-..." | Re-trigger Greptile

Comment on lines +34 to +35
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True" # test-quality-ok: kyma not on remote map yet
litellm.model_cost = litellm.get_model_cost_map(url="") # test-quality-ok: reload after env set

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Global test state leaks

This module fixture never restores the environment or cost map, so later tests inherit stale state and can fail depending on execution order

Comment on lines +1 to +13
"""
Tests for Kyma API provider configuration and integration.

Kyma API (https://kymaapi.com) is an OpenAI-compatible LLM gateway. Registered
here as a JSON-configured provider (litellm/llms/openai_like/providers.json).

No real network calls: config/registration assertions use JSONProviderRegistry
directly, and the routing/cost assertions use litellm's own `mock_response`
completion path (see litellm/main.py) rather than patching internals -- the
previous submission (PR #25543) patched `litellm.main.completion`, which is
never called because `litellm.completion` is bound at import time via
`from .main import *`, so the mock silently never fired.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Prohibited explanatory comments

These docstrings narrate provider history and test mechanics, violating the repository directive to reserve comments for necessary complex logic or tool instructions. This requirement must be satisfied before merging

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +59429 to +59430
"input_cost_per_token_above_256k_tokens": 1.755e-06,
"output_cost_per_token_above_256k_tokens": 5.265e-06,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Pricing tier is unreachable

This model caps input at 131,072 tokens but defines pricing above 256k, so the tier can never apply and leaves misleading catalog data

Knowledge Base Used: Provider adapters and capabilities

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

test_kyma_provider.py: the module-scoped autouse fixture set
LITELLM_LOCAL_MODEL_COST_MAP and litellm.model_cost without restoring
either, and never cleared the lru_cache behind get_model_info, so later
tests in the same process could see kyma leaked into their view of the
map. Replaced with a function-scoped fixture using monkeypatch (auto-
reverts both), requested only by the two tests that need it, plus an
explicit cache_clear before and after.

Dropped narrative comments and docstrings not covered by this repo's
CLAUDE.md comment policy.

model_prices_and_context_window.json (+ backup): kyma/qwen-3.6-plus caps
max_input_tokens at 131072 but carried input/output_cost_per_token_above_256k_tokens
tiers that could never be reached. Removed both; entry count is still 70.

model_prices_and_context_window.schema.json: regenerated. The only diff is
input/output_cost_per_token_above_32k_tokens, from kyma/qwen3.7-flash's own
(reachable) 32k tier, which no prior entry in the file used.
@sonpiaz

sonpiaz commented Sep 4, 2026

Copy link
Copy Markdown
Author

Addressed the review and the schema check in be76d05:

  • Test fixture: now function-scoped with monkeypatch (env and litellm.model_cost restored automatically) and _cached_get_model_info.cache_clear() before and after; only the two tests that need the cost map request it.
  • Comments: removed the narrative docstrings and inline comments; the file is code and names only.
  • Pricing: removed the above_256k tier on kyma/qwen-3.6-plus (its max_input_tokens is 131,072, so the tier could never apply) in both the root file and the backup. All other tiers are reachable.
  • Schema: regenerated model_prices_and_context_window.schema.json with ci_cd/generate_model_prices_schema.py; the two new keys come from the valid 32k tier on kyma/qwen3.7-flash. --check passes locally.

Local gates rerun green: 15/15 provider tests, ruff check and format, the quality, type-check and type-discipline gates, import-safety and circular-import checks.

…ty tests

model_prices_and_context_window.json (+ backup): every kyma/claude-* entry
was missing capability flags that the repo's cross-provider tests require
to match the canonical anthropic entry for the same model. Copied from the
canonical root entry (litellm_provider, prices and context fields excluded,
since kyma legitimately has its own):

- claude-fable-5, claude-fable-5.1: supports_adaptive_thinking,
  thinking_always_on, supports_sampling_params=false
- claude-opus-4-7: supports_adaptive_thinking, supports_sampling_params=false,
  prompt_cache_min_tokens=2048
- claude-opus-5, claude-opus-5-fast: supports_adaptive_thinking,
  supports_sampling_params=false, prompt_cache_min_tokens=512
- claude-sonnet-4-6: supports_adaptive_thinking, prompt_cache_min_tokens=1024
- claude-sonnet-5: supports_adaptive_thinking, supports_sampling_params=false,
  prompt_cache_min_tokens=1024
- claude-haiku-4-5: prompt_cache_min_tokens=4096

claude-fable-5/5.1 keep supports_prompt_caching=false as already set, so no
prompt_cache_min_tokens was added there. Entry count is still 70.
ci_cd/generate_model_prices_schema.py --check stays green with no
regeneration needed: every added key already existed elsewhere in the file.

tests/test_litellm/test_utils.py: INTENDED_SCHEMA in
test_aaamodel_prices_and_context_window_json_is_valid did not allow
input/output_cost_per_token_above_32k_tokens. That threshold is real
(kyma/qwen3.7-flash's own 32k tier, the only model in the file that uses
it) and the runtime cost calculator already handles arbitrary thresholds
generically, so the fix is widening this hand-maintained allowlist to
match the data, the same way 128k/200k/256k/272k/512k must each have been
added when a model first needed them.
@sonpiaz

sonpiaz commented Sep 4, 2026

Copy link
Copy Markdown
Author

a57c09c makes the kyma/claude-* entries carry the same capability flags as the canonical Anthropic entries (supports_adaptive_thinking, thinking_always_on, supports_sampling_params, prompt_cache_min_tokens per model), which the cross-provider config tests require, and adds the above_32k tier keys to the intended-schema allowlist in test_utils.py since kyma/qwen3.7-flash is the first entry with a 32k threshold. All seven test_claude_*_config.py files, the schema validity test, the provider tests (100 total) and the schema --check pass locally.

- kyma/qwen-3.6-plus: max_input_tokens 131072 -> 1000000, max_tokens and
  max_output_tokens 32768 -> 65536. Restores the input_cost_per_token_above_256k_tokens
  / output_cost_per_token_above_256k_tokens tier removed earlier in review for being
  unreachable on the old 131k window; it is reachable on the corrected 1M window, so
  the tier fields come back with the same field names already used by kyma/qwen-3.7-plus.
- kyma/gpt-oss-120b: supports_reasoning false -> true
- kyma/llama-3.3-70b: supports_reasoning true -> false
- kyma/deepseek-v3: unchanged, source registry confirms supports_reasoning stays true

Source: upstream registry audit merged 2026-09-04. Schema regenerated via
ci_cd/generate_model_prices_schema.py --check (no new keys, above_256k tier fields
already present from qwen-3.7-plus); root and backup price files re-verified identical.
@sonpiaz
sonpiaz requested a review from a team September 5, 2026 01:42
@sonpiaz

sonpiaz commented Sep 5, 2026

Copy link
Copy Markdown
Author

Pushed f31ee53 to sync three kyma/* entries with a correction just made to the source catalog:

  • kyma/qwen-3.6-plus: max_input_tokens 131072 → 1000000, max_tokens/max_output_tokens 32768 → 65536. This also makes the input_cost_per_token_above_256k_tokens / output_cost_per_token_above_256k_tokens tier reachable again — it was removed in an earlier commit on this PR because the model's window capped at 131k and the tier could never fire. The tier is back with the same field names already used by kyma/qwen-3.7-plus, and ci_cd/generate_model_prices_schema.py --check confirms no new schema keys are needed.
  • kyma/gpt-oss-120b: supports_reasoning false → true
  • kyma/llama-3.3-70b: supports_reasoning true → false
  • kyma/deepseek-v3: unchanged — the source catalog confirms supports_reasoning: true still holds

Live checks against the corrected values, run just now:

  • A 473,189-token prompt to qwen-3.6-plus (well past the 256k threshold) returned 200, and usage.cost (0.8305) matches the above_256k tier rate, not the base rate (which would have priced it at ~0.31) — confirms the restored tier is live and reachable.
  • An image request to qwen-3.6-plus returned 200 with the correct answer, confirming supports_vision: true holds on the wider window.

Local suite green: 15/15 test_kyma_provider.py, all 7 test_claude_*_config.py files (84 tests, unaffected by this change but re-run for safety), test_aaamodel_prices_and_context_window_json_is_valid, and the schema --check.

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:49
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:43
mateo-berri pushed a commit that referenced this pull request Oct 29, 2026
Adds Kyma API (kyma/<model>) as a JSON-configured OpenAI-compatible provider. Spend reads the usage.cost Kyma reports, with 83 catalog rows as the fallback price, and image and audio routes refuse before calling Kyma. Carries over #39799 with its author's commits kept
@mateo-berri

Copy link
Copy Markdown
Contributor

Thanks @sonpiaz, your provider merged in #48756 with refreshed prices and billing from Kyma's reported cost. Closing this one as superseded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants