litellm/.github
Gabriel Creti 0946b7416c
feat(gradium): add text-to-speech support for /v1/audio/speech (#46427)
* feat(gradium): add text-to-speech support for /v1/audio/speech

Gradium (https://gradium.ai) is a voice AI provider whose TTS had no
LiteLLM route. Adds it as a first-class TTS provider behind the existing
BaseTextToSpeechConfig seam, so `litellm.speech(model="gradium/default")`
and the proxy's /v1/audio/speech both work.

The provider targets Gradium's REST TTS endpoint
(POST /api/post/speech/tts) rather than its Python SDK, so the call
flows through base_llm_http_handler and keeps retries, logging and cost
tracking that an SDK-internal HTTP client would bypass.

Notes on the mapping:
- `only_audio: true` is always sent. Without it Gradium answers a
  line-delimited JSON message stream instead of audio bytes, which
  /v1/audio/speech callers cannot read.
- The six canonical OpenAI voice names map to Gradium library voice IDs;
  anything else is forwarded verbatim, so raw Gradium voice IDs work.
- Gradium has no mp3/aac/flac encoder, so those response_formats raise
  UnsupportedParamsError instead of silently returning mislabeled audio.
  `litellm.drop_params` falls back to the default format.
- Pre-stream failures come back as HTTP 500 with a plain-text body, so
  the response transform raises rather than handing the caller an opaque
  binary payload.
- Cost is per character of input text (1 credit/char), priced from the
  published add-on credit rate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(gradium): satisfy CI gates and handle /api-suffixed api_base

- register the provider in provider_endpoints_support.json and claim
  tests/unit/llms/gradium in the llms-providers shard, so the provider
  documentation and CI/shard coverage gates see it
- rework the transformation to build its params and request body
  functionally rather than by mutation, so it clears the type-discipline
  rules; the suppressions that remain are the signatures
  BaseTextToSpeechConfig fixes and the dicts its return types require
- get_complete_url now tolerates an api_base that already ends in /api.
  Gradium documents its regional bases that way
  (https://eu.api.gradium.ai/api), and pasting one produced
  /api/api/post/speech/tts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(gradium): cover the remaining branches, format under the pinned ruff

- ruff format with the pinned 0.15.3 (the suppression comments were long
  enough to push their lines over the limit and get them wrapped)
- cover get_supported_openai_params, get_error_class, the explicit
  api_base/api_key path, and both missing-voice paths, taking the
  provider to 100% patch coverage

The missing-voice tests record where each guard actually fires:
map_openai_params raises ValueError first (same as elevenlabs), so
speech()'s own BadRequestError is reachable only when the provider
config manager returns None.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(gradium): use the local_model_cost_map fixture for the cost test

The cost test wrote litellm.model_cost directly, which the test-quality
gate flags (TQ005): it is a process-wide global, and the leak is exactly
what the save/restore conftest exists to undo. The existing
local_model_cost_map fixture does the same setup with teardown, so the
suite no longer depends on LITELLM_LOCAL_MODEL_COST_MAP being exported.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(gradium): clear the basedpyright and Add Model dropdown gates

- add a provider_create_fields.json entry so gradium appears in the
  proxy UI's Add Model dropdown; test_public_endpoints asserts every
  LlmProviders member is listed there
- parameterize the dict/list annotations copied from
  BaseTextToSpeechConfig and type gradium_models, which basedpyright
  counted as new Unknown-type errors against the merge-base ceiling
- suppress the untyped-argument errors on the shared TTS handler call;
  every provider branch of speech() carries the same ones
- keep extra_body support, matching elevenlabs and minimax, and cover it
  with a test

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(gradium): take api_key and api_base from the model only

The API key and base are set by whoever creates the model, like any other
deployment credential. Drop the GRADIUM_API_KEY / GRADIUM_API_BASE
environment fallbacks, the litellm.api_key fallback (which could send an
unrelated provider's global key to Gradium) and the hardcoded default
base URL; a missing value now raises a clear error.

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(gradium): stream text-to-speech audio when stream is true

#46222 made streamed speech opt-in per provider through
supports_streaming. Gradium's REST TTS endpoint already sends audio as
it is synthesized, so the config opts in and speech() forwards
stream=True to the shared handler. Without stream the clip is still
read in full before it is returned.

Co-Authored-By: Claude <noreply@anthropic.com>

* chore(gradium): regenerate provider endpoint support

provider_endpoints_support.json and its backup are now generated from
the cost map, so Gradium's hand-written entry was stale and missing
from the backup.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(gradium): honor drop_params, reject speed and instructions, bill every character

Gradium counts every input character, spaces included, so the response reports billed_characters and the shared cost path no longer under-bills by the stripped whitespace

A deployment's drop_params now drops an unsupported response_format, speed or instructions. Without it those params answer 400, the litellm convention for a param the provider cannot honor

The Pro Voice Clone row is removed because Gradium has no such model name. The XS add-on rate is $7 per 100k credits, and the Add Model form now asks for the API base

* fix(gradium): accept native formats, map current OpenAI voices, answer 400 on a missing voice

Calls Gradium's documented /api/speech/tts path, passes ulaw_8000, alaw_8000 and the pcm_* rates through with audio content types, maps ash, ballad, coral, sage, verse, marin and cedar, prices gradium/gradium-tts-beta, and types the tests

* fix(gradium): map OpenAI voices to English voices, forward json_config, accept speed 1.0

Missing api_key now answers 401 and a missing api_base answers 500 without a traceback

* fix(gradium): ignore a non-object extra_body and keep a top-level json_config

A non-object extra_body no longer answers 500, and a null json_config in
extra_body no longer erases the top-level value. The cost map drops the advice
to override input_cost_per_character, which speech cost ignores today, and adds
gradium/gradium-tts-202602, Gradium's previous model, at the same rate. The
async speech test now checks the request body sent on both the streamed and
buffered paths.

* fix(gradium): read json_config from any mapping extra_body

A read-only mapping such as MappingProxyType passed as extra_body is now
read like a dict, as it was before the non-object check. The non-object
test also sends a top-level json_config so it fails if that check drops
every caller field

* fix(gradium): answer 502 for a 200 response that is not audio

Only a missing content type or application/octet-stream, which Gradium
sends for pcm, ulaw and alaw, is relabeled as audio. Any other 200, such
as JSON or HTML, now raises a 502 instead of reaching the caller labeled
audio/pcm and being billed. Tests also pin case-insensitive voice names,
trimmed voices and extra_body's json_config winning over the top level

* fix(gradium): release the upstream response when rejecting a non-audio reply

A streamed 200 that is not audio was raised as a 502 without closing the
response, so the sync and async speech paths could keep the connection.
Both paths now close it before raising

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-21 23:51:27 +00:00
..
actions Revert "ci: reuse Rust bridge builds across PR pushes and refresh the Cargo cache (#52718)" (#52770) 2026-11-18 23:07:25 -08:00
assets/scaledown chore(repo): remove committed Lens review screenshots (#53169) 2026-11-20 12:31:32 -08:00
codeql ci(codeql): run the default suite on full scans and security-extended on PRs (#45149) 2026-10-07 13:24:28 -07:00
e2e-stack test(mcp): replace the live Linear MCP OAuth e2e tests with integration coverage (#47154) 2026-10-17 14:29:59 -07:00
ISSUE_TEMPLATE ci: classify new issues into domain, provider, kind, priority and lift labels 2026-09-18 11:37:55 -07:00
linters chore(lint): flag conditionals with more than 3 boolean clauses via ruff PLR0916 (#51964) 2026-11-15 16:53:38 -05:00
packaging chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
pr-assets feat(customer-portal): complete hierarchy management (#51521) 2026-11-13 17:58:34 +00:00
prompts ci: classify new issues into domain, provider, kind, priority and lift labels 2026-09-18 11:37:55 -07:00
PULL_REQUEST_TEMPLATE docs(review): require live QA across shared translation routes (#52631) 2026-11-18 13:19:32 -08:00
screenshots
scripts ci(lint): run the fast lint checks on pull requests again without compiling Rust (#53421) 2026-11-21 14:17:30 -08:00
semgrep/rules chore: move config and docs off the repo root (#50966) 2026-11-11 18:29:35 -08:00
workflows feat(gradium): add text-to-speech support for /v1/audio/speech (#46427) 2026-11-21 23:51:27 +00:00
AGENTS.md ci(lint): run the fast lint checks on pull requests again without compiling Rust (#53421) 2026-11-21 14:17:30 -08:00
ci-coverage-allowlist.yml feat(docker): add a FIPS 140-3 proxy image (#50330) 2026-11-19 17:16:05 -08:00
codecov.yml chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
CODEOWNERS feat(spend-logs): rust spend log row builder (#52161) 2026-11-20 16:31:03 -08:00
CONTRIBUTING.md chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00
dependabot.yaml
deploy-on-aws.png
deploy-on-gcp.png
deploy-to-aws.png
FUNDING.yml
gitguardian.yaml chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00
grype.yaml chore: move config and docs off the repo root (#50966) 2026-11-11 18:29:35 -08:00
issue-labels.json ci(issue-classifier): name every workflow, script and job after the issue it works on 2026-09-18 11:37:55 -07:00
mutmut-coverage.rc fix(ci): let the mutation workflow find covered lines so it generates mutants 2026-08-25 23:16:40 -07:00
osv-scanner.toml ci(osv): ignore picomatch GHSA-fc5q-39xc-vjpf until 2026-11-24 (#52337) 2026-11-17 21:18:01 +00:00
SECURITY.md chore: move config and docs off the repo root (#50966) 2026-11-11 18:29:35 -08:00
template.yaml fix(proxy): drop legacy telemetry key from persisted WORKER_CONFIG before initialize 2026-09-20 03:14:11 +00:00