Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Provider-specific request parameters for the text and chat models (TEXT_MODEL_EXTRA_BODY, CHAT_MODEL_EXTRA_BODY)

Murtaza Nasir187260bf0d13
diff --git a/config/env.asr.example b/config/env.asr.example
index 25cddca4..8a283801 100644
--- a/config/env.asr.example
+++ b/config/env.asr.example
@@ -68,6 +68,17 @@ GPT5_VERBOSITY=medium
# CHAT_GPT5_REASONING_EFFORT=medium
# CHAT_GPT5_VERBOSITY=medium
+# --- Provider-Specific Request Parameters (Optional) ---
+# A JSON object added to every request to the model, for settings such as
+# reasoning effort that differ between providers. Examples:
+# OpenRouter: {"reasoning": {"effort": "low"}}
+# OpenAI: {"reasoning_effort": "minimal"}
+# vLLM or llama.cpp, Qwen3: {"chat_template_kwargs": {"enable_thinking": false}}
+# CHAT_MODEL_EXTRA_BODY is used only for a separately configured chat model.
+# See docs/admin-guide/model-configuration.md.
+# TEXT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+# CHAT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+
# --- LLM Timeout & Retry ---
# Read timeout for LLM requests in seconds (default 600). Increase for local
# models (Ollama, vLLM) that need more time for long transcripts.
diff --git a/config/env.transcription.example b/config/env.transcription.example
index 1c8e635b..031d167a 100644
--- a/config/env.transcription.example
+++ b/config/env.transcription.example
@@ -77,6 +77,17 @@ GPT5_VERBOSITY=medium
# CHAT_MODEL_BASE_URL=https://openrouter.ai/api/v1
# CHAT_MODEL_NAME=openai/gpt-4o
+# --- Provider-Specific Request Parameters (Optional) ---
+# A JSON object added to every request to the model, for settings such as
+# reasoning effort that differ between providers. Examples:
+# OpenRouter: {"reasoning": {"effort": "low"}}
+# OpenAI: {"reasoning_effort": "minimal"}
+# vLLM or llama.cpp, Qwen3: {"chat_template_kwargs": {"enable_thinking": false}}
+# CHAT_MODEL_EXTRA_BODY is used only for a separately configured chat model.
+# See docs/admin-guide/model-configuration.md.
+# TEXT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+# CHAT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+
# =============================================================================
# CONNECTOR SELECTION (Auto-detected if not set)
# =============================================================================
diff --git a/config/env.whisper.example b/config/env.whisper.example
index 8179569d..29537c5b 100644
--- a/config/env.whisper.example
+++ b/config/env.whisper.example
@@ -70,6 +70,17 @@ GPT5_VERBOSITY=medium
# CHAT_GPT5_REASONING_EFFORT=medium
# CHAT_GPT5_VERBOSITY=medium
+# --- Provider-Specific Request Parameters (Optional) ---
+# A JSON object added to every request to the model, for settings such as
+# reasoning effort that differ between providers. Examples:
+# OpenRouter: {"reasoning": {"effort": "low"}}
+# OpenAI: {"reasoning_effort": "minimal"}
+# vLLM or llama.cpp, Qwen3: {"chat_template_kwargs": {"enable_thinking": false}}
+# CHAT_MODEL_EXTRA_BODY is used only for a separately configured chat model.
+# See docs/admin-guide/model-configuration.md.
+# TEXT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+# CHAT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+
# --- LLM Timeout & Retry ---
# Read timeout for LLM requests in seconds (default 600). Increase for local
# models (Ollama, vLLM) that need more time for long transcripts.
diff --git a/config/env.whisperx.example b/config/env.whisperx.example
index e43978bf..3e72a9ea 100644
--- a/config/env.whisperx.example
+++ b/config/env.whisperx.example
@@ -84,6 +84,17 @@ GPT5_VERBOSITY=medium
# CHAT_GPT5_REASONING_EFFORT=medium
# CHAT_GPT5_VERBOSITY=medium
+# --- Provider-Specific Request Parameters (Optional) ---
+# A JSON object added to every request to the model, for settings such as
+# reasoning effort that differ between providers. Examples:
+# OpenRouter: {"reasoning": {"effort": "low"}}
+# OpenAI: {"reasoning_effort": "minimal"}
+# vLLM or llama.cpp, Qwen3: {"chat_template_kwargs": {"enable_thinking": false}}
+# CHAT_MODEL_EXTRA_BODY is used only for a separately configured chat model.
+# See docs/admin-guide/model-configuration.md.
+# TEXT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+# CHAT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+
# --- Transcription Service (WhisperX ASR Endpoint) ---
# New connector architecture auto-detects ASR mode when ASR_BASE_URL is set.
# USE_ASR_ENDPOINT=true is deprecated but still works for backwards compatibility.
diff --git a/docs/admin-guide/model-configuration.md b/docs/admin-guide/model-configuration.md
index 32b38e2c..c93745ec 100644
--- a/docs/admin-guide/model-configuration.md
+++ b/docs/admin-guide/model-configuration.md
@@ -376,6 +376,33 @@ After changing model configuration:
4. Test the chat feature
5. Monitor logs for any errors or warnings
+## Provider-Specific Request Parameters
+
+Reasoning ("thinking") is controlled differently by each provider, and some models think by default, which makes summaries and titles slower and more expensive. `TEXT_MODEL_EXTRA_BODY` holds a JSON object whose fields are added to every request to the text model. `CHAT_MODEL_EXTRA_BODY` is the same setting for a separately configured chat model.
+
+```bash
+# Turn off thinking for a Qwen3 model on vLLM, SGLang or llama.cpp
+TEXT_MODEL_EXTRA_BODY={"chat_template_kwargs": {"enable_thinking": false}}
+```
+
+The fields are sent unchanged, so they must be ones your provider and model accept:
+
+| Provider | Example |
+|----------|---------|
+| OpenRouter, any reasoning model | `{"reasoning": {"effort": "low"}}`, or `{"reasoning": {"enabled": false}}` to turn reasoning off |
+| OpenAI (o-series, GPT-5) | `{"reasoning_effort": "minimal"}` |
+| vLLM, SGLang or llama.cpp, Qwen3 and similar models | `{"chat_template_kwargs": {"enable_thinking": false}}` |
+| vLLM, gpt-oss | `{"reasoning_effort": "low"}` |
+
+The name of the `chat_template_kwargs` field depends on the model's chat template and is given on the model card.
+
+- The fields are added after Speakr's own parameters and replace any with the same name, including the GPT-5 settings and `max_tokens`.
+- When chat uses the text model, `TEXT_MODEL_EXTRA_BODY` applies to chat as well. A separately configured chat model does not inherit it.
+- In `.env`, the JSON is written without surrounding quotes.
+- If the value is not a JSON object, requests to that model fail with an error that names the variable.
+- When a provider rejects a request, the log lists the fields added by this setting. Some servers ignore fields they do not recognise, so compare response times or token counts before and after a change to confirm its effect.
+- Reasoning tokens are counted as completion tokens in the token statistics. The reasoning text is not stored with summaries, titles or chat answers.
+
## Environment Variables Reference
```bash
@@ -417,6 +444,11 @@ CHAT_MODEL_NAME=openai/gpt-4o
# Chat-specific GPT-5 settings (optional - falls back to GPT5_* if not set)
CHAT_GPT5_REASONING_EFFORT=medium # minimal, low, medium, high
CHAT_GPT5_VERBOSITY=medium # low, medium, high
+
+# Provider-specific request parameters, a JSON object (optional)
+# See Provider-Specific Request Parameters above
+TEXT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
+CHAT_MODEL_EXTRA_BODY={"reasoning": {"effort": "low"}}
```
## Prefix-Cache-Friendly Prompts (`PREFIX_CACHE_OPTIMIZED_PROMPTS`)
diff --git a/src/api/recordings.py b/src/api/recordings.py
index 890ac93e..7b75dddf 100644
--- a/src/api/recordings.py
+++ b/src/api/recordings.py
@@ -3195,8 +3195,6 @@ def chat_incognito():
from src.services.recording_chat import build_chat_messages
messages, _ = build_chat_messages(recording, current_user, user_message, message_history)
- # Get model info
- chat_model = os.environ.get('TEXT_MODEL_NAME', os.environ.get('OPENAI_CHAT_MODEL', 'gpt-4o-mini'))
user_id = current_user.id
current_app.logger.info(f"[Incognito Chat] User {user_id} sending message")
@@ -3207,12 +3205,8 @@ def chat_incognito():
def generate():
"""Stream the chat response."""
try:
- response = chat_client.chat.completions.create(
- model=chat_model,
- messages=messages,
- temperature=chat_temperature,
- stream=True
- )
+ # No user_id, so nothing is tracked for incognito
+ response = call_chat_completion(messages, temperature=chat_temperature, stream=True)
for chunk in response:
if chunk.choices and len(chunk.choices) > 0:
diff --git a/src/services/llm.py b/src/services/llm.py
index 1ac19315..678da7bb 100644
--- a/src/services/llm.py
+++ b/src/services/llm.py
@@ -8,7 +8,7 @@ import json
import time
import logging
import httpx
-from openai import OpenAI, APITimeoutError
+from openai import OpenAI, APITimeoutError, BadRequestError
# Use standard logging instead of current_app.logger for context independence
logger = logging.getLogger(__name__)
@@ -84,6 +84,30 @@ CHAT_MODEL_NAME = os.environ.get("CHAT_MODEL_NAME")
CHAT_GPT5_REASONING_EFFORT = os.environ.get("CHAT_GPT5_REASONING_EFFORT")
CHAT_GPT5_VERBOSITY = os.environ.get("CHAT_GPT5_VERBOSITY")
+# Provider-specific request parameters, as a JSON object merged into the body
+# of every request to the model (OpenAI SDK extra_body). Reasoning controls
+# differ by provider and model (reasoning_effort, OpenRouter's reasoning
+# object, chat_template_kwargs on vLLM), so they are set here, not mapped.
+def _parse_extra_body(env_var):
+ """Return (parameters, error) for a JSON object in env_var."""
+ raw = os.environ.get(env_var, "").strip()
+ if not raw:
+ return {}, None
+ try:
+ value = json.loads(raw)
+ except ValueError as e:
+ return {}, f"{env_var} is not valid JSON ({e})"
+ if not isinstance(value, dict):
+ return {}, f"{env_var} must be a JSON object, such as {{\"reasoning_effort\": \"low\"}}"
+ return value, None
+
+
+TEXT_MODEL_EXTRA_BODY, TEXT_MODEL_EXTRA_BODY_ERROR = _parse_extra_body("TEXT_MODEL_EXTRA_BODY")
+CHAT_MODEL_EXTRA_BODY, CHAT_MODEL_EXTRA_BODY_ERROR = _parse_extra_body("CHAT_MODEL_EXTRA_BODY")
+for _error in (TEXT_MODEL_EXTRA_BODY_ERROR, CHAT_MODEL_EXTRA_BODY_ERROR):
+ if _error:
+ logger.error(f"{_error}; requests to that model will fail until it is corrected.")
+
# Streaming options - disable for LLM servers that don't support OpenAI's stream_options
ENABLE_STREAM_OPTIONS = os.environ.get("ENABLE_STREAM_OPTIONS", "true").lower() == "true"
@@ -130,6 +154,11 @@ def get_chat_config():
# A separate chat model does not inherit GPT5_FORCE_MODE: it may
# be a different (non-GPT-5) model than the main text model.
'gpt5_force': _gpt5_mode_forced("CHAT_GPT5_FORCE_MODE"),
+ # Like GPT5_FORCE_MODE, the text model's parameters are not
+ # inherited: they may not suit a different model or server.
+ 'extra_body': CHAT_MODEL_EXTRA_BODY,
+ 'extra_body_variable': 'CHAT_MODEL_EXTRA_BODY',
+ 'extra_body_error': CHAT_MODEL_EXTRA_BODY_ERROR,
}
return {
'api_key': TEXT_MODEL_API_KEY,
@@ -138,6 +167,9 @@ def get_chat_config():
'gpt5_reasoning_effort': os.environ.get("GPT5_REASONING_EFFORT", "medium"),
'gpt5_verbosity': os.environ.get("GPT5_VERBOSITY", "medium"),
'gpt5_force': _gpt5_mode_forced(),
+ 'extra_body': TEXT_MODEL_EXTRA_BODY,
+ 'extra_body_variable': 'TEXT_MODEL_EXTRA_BODY',
+ 'extra_body_error': TEXT_MODEL_EXTRA_BODY_ERROR,
}
@@ -208,6 +240,26 @@ except Exception as chat_client_init_e:
chat_client = client
+def _add_extra_body(completion_args, extra_body, error):
+ """Merge the configured request parameters into completion_args.
+
+ They are applied last, so they take precedence over the parameters set
+ above (temperature, max_tokens, the GPT-5 settings)."""
+ if error:
+ raise ValueError(error)
+ if extra_body:
+ completion_args["extra_body"] = dict(extra_body)
+
+
+def _log_rejected_parameters(error, variable, extra_body):
+ """Name the request parameters setting when the provider rejects a request."""
+ if extra_body and isinstance(error, BadRequestError):
+ logger.error(
+ f"The model server rejected the request. {variable} adds "
+ f"{', '.join(sorted(extra_body))}; check that the server accepts these parameters."
+ )
+
+
def is_gpt5_model(model_name):
"""
Check if the model is a GPT-5 series model that requires special API parameters.
@@ -313,6 +365,8 @@ def call_llm_completion(messages, temperature=0.7, response_format=None, stream=
if response_format:
completion_args["response_format"] = response_format
+ _add_extra_body(completion_args, TEXT_MODEL_EXTRA_BODY, TEXT_MODEL_EXTRA_BODY_ERROR)
+
# Make the resolved max_tokens visible in logs so users can confirm
# their SUMMARY_MAX_TOKENS / CHAT_MAX_TOKENS / etc. settings actually
# took effect for a given operation. The "key" used here is
@@ -373,6 +427,7 @@ def call_llm_completion(messages, temperature=0.7, response_format=None, stream=
raise
except Exception as e:
logger.error(f"LLM API call failed: {e}")
+ _log_rejected_parameters(e, 'TEXT_MODEL_EXTRA_BODY', TEXT_MODEL_EXTRA_BODY)
raise
@@ -403,9 +458,6 @@ def call_chat_completion(messages, temperature=0.7, response_format=None, stream
if not effective_client:
raise ValueError("Chat LLM client not initialized")
- if not chat_config['api_key']:
- raise ValueError("Chat model API key not configured")
-
# Check budget before making the call
if user_id and operation_type:
try:
@@ -461,6 +513,8 @@ def call_chat_completion(messages, temperature=0.7, response_format=None, stream
if tool_choice:
completion_args["tool_choice"] = tool_choice
+ _add_extra_body(completion_args, chat_config['extra_body'], chat_config['extra_body_error'])
+
# Visibility: surface the resolved budget per call so admins can
# confirm CHAT_MAX_TOKENS or per-call overrides took effect.
budget_key = 'max_completion_tokens' if using_gpt5 else 'max_tokens'
@@ -514,6 +568,7 @@ def call_chat_completion(messages, temperature=0.7, response_format=None, stream
raise
except Exception as e:
logger.error(f"Chat LLM API call failed: {e}")
+ _log_rejected_parameters(e, chat_config['extra_body_variable'], chat_config['extra_body'])
raise
diff --git a/src/tasks/processing.py b/src/tasks/processing.py
index 98db89cd..fb68f0f6 100644
--- a/src/tasks/processing.py
+++ b/src/tasks/processing.py
@@ -2745,9 +2745,8 @@ Title:"""
if user_output_language:
system_message_content += f" Ensure your response is in {user_output_language}."
- # Use call_llm_completion without user_id tracking for incognito
- completion = client.chat.completions.create(
- model=TEXT_MODEL_NAME,
+ # No user_id, so nothing is tracked for incognito
+ completion = call_llm_completion(
messages=[
{"role": "system", "content": system_message_content},
{"role": "user", "content": prompt_text}
@@ -2820,9 +2819,8 @@ Summarization Instructions:
current_app.logger.info(f"[Incognito] Generating summary...")
- # Use client directly without user tracking for incognito
- completion = client.chat.completions.create(
- model=TEXT_MODEL_NAME,
+ # No user_id, so nothing is tracked for incognito
+ completion = call_llm_completion(
messages=[
{"role": "system", "content": system_message_content},
{"role": "user", "content": prompt_text}
diff --git a/tests/test_cov_llm.py b/tests/test_cov_llm.py
index 2535778a..c492476b 100644
--- a/tests/test_cov_llm.py
+++ b/tests/test_cov_llm.py
@@ -463,15 +463,16 @@ def test_call_chat_completion_no_client(monkeypatch):
call_chat_completion([{"role": "user", "content": "hi"}])
-def test_call_chat_completion_no_api_key(monkeypatch):
+def test_call_chat_completion_without_api_key(monkeypatch):
+ """A local server often needs no key (#403), for chat as for summaries."""
fake = FakeClient(return_value=make_completion("ok"))
monkeypatch.setattr(llm, "chat_client", fake)
monkeypatch.setattr(llm, "client", fake)
monkeypatch.setattr(llm, "CHAT_MODEL_API_KEY", None)
monkeypatch.setattr(llm, "CHAT_MODEL_NAME", None)
monkeypatch.setattr(llm, "TEXT_MODEL_API_KEY", None)
- with pytest.raises(ValueError, match="API key not configured"):
- call_chat_completion([{"role": "user", "content": "hi"}])
+ response = call_chat_completion([{"role": "user", "content": "hi"}])
+ assert response.choices[0].message.content == "ok"
def test_call_chat_completion_success(monkeypatch):
diff --git a/tests/test_llm_extra_body.py b/tests/test_llm_extra_body.py
new file mode 100644
index 00000000..52af9c2d
--- /dev/null
+++ b/tests/test_llm_extra_body.py
@@ -0,0 +1,138 @@
+"""Provider-specific request parameters (TEXT_MODEL_EXTRA_BODY and
+CHAT_MODEL_EXTRA_BODY), merged into every request as extra_body."""
+
+from types import SimpleNamespace
+from unittest.mock import MagicMock
+
+import httpx
+import openai
+import pytest
+
+import src.services.llm as llm
+
+
+def _completion(content="ok"):
+ return SimpleNamespace(choices=[SimpleNamespace(message=SimpleNamespace(content=content),
+ finish_reason="stop")], usage=None)
+
+
+def _client(monkeypatch, *names, **kwargs):
+ create = MagicMock(return_value=_completion(), **kwargs)
+ fake = SimpleNamespace(chat=SimpleNamespace(completions=SimpleNamespace(create=create)))
+ for name in names:
+ monkeypatch.setattr(llm, name, fake)
+ return create
+
+
+def text_model(monkeypatch):
+ monkeypatch.setattr(llm, "TEXT_MODEL_NAME", "qwen3")
+ monkeypatch.setattr(llm, "TEXT_MODEL_BASE_URL", "http://vllm:8000/v1")
+ monkeypatch.setattr(llm, "TEXT_MODEL_API_KEY", None)
+ monkeypatch.setattr(llm, "CHAT_MODEL_NAME", None)
+ monkeypatch.setattr(llm, "CHAT_MODEL_API_KEY", None)
+ monkeypatch.setattr(llm, "CHAT_MODEL_BASE_URL", None)
+ monkeypatch.delenv("GPT5_FORCE_MODE", raising=False)
+
+
[email protected]("raw, expected", [
+ ("", ({}, None)),
+ ('{"chat_template_kwargs": {"enable_thinking": false}}',
+ ({"chat_template_kwargs": {"enable_thinking": False}}, None)),
+ ('{"reasoning": {"effort": "low"}}', ({"reasoning": {"effort": "low"}}, None)),
+])
+def test_parse_valid_settings(monkeypatch, raw, expected):
+ monkeypatch.setenv("TEXT_MODEL_EXTRA_BODY", raw)
+ assert llm._parse_extra_body("TEXT_MODEL_EXTRA_BODY") == expected
+
+
[email protected]("raw, message", [
+ ("{reasoning: low}", "is not valid JSON"),
+ ('["low"]', "must be a JSON object"),
+ ('"low"', "must be a JSON object"),
+])
+def test_parse_invalid_settings(monkeypatch, raw, message):
+ monkeypatch.setenv("TEXT_MODEL_EXTRA_BODY", raw)
+ value, error = llm._parse_extra_body("TEXT_MODEL_EXTRA_BODY")
+ assert value == {} and message in error and "TEXT_MODEL_EXTRA_BODY" in error
+
+
+def test_no_setting_sends_no_extra_body(monkeypatch, text_model):
+ create = _client(monkeypatch, "client")
+ monkeypatch.setattr(llm, "TEXT_MODEL_EXTRA_BODY", {})
+ llm.call_llm_completion([{"role": "user", "content": "q"}])
+ assert "extra_body" not in create.call_args.kwargs
+
+
+def test_text_model_parameters_are_sent(monkeypatch, text_model):
+ create = _client(monkeypatch, "client")
+ body = {"chat_template_kwargs": {"enable_thinking": False}}
+ monkeypatch.setattr(llm, "TEXT_MODEL_EXTRA_BODY", body)
+ llm.call_llm_completion([{"role": "user", "content": "q"}], max_tokens=100)
+ kwargs = create.call_args.kwargs
+ assert kwargs["extra_body"] == body
+ assert kwargs["extra_body"] is not body # a copy per request
+ assert kwargs["max_tokens"] == 100
+
+
+def test_parameters_are_added_to_gpt5_requests(monkeypatch, text_model):
+ create = _client(monkeypatch, "client")
+ monkeypatch.setenv("GPT5_FORCE_MODE", "true")
+ monkeypatch.setattr(llm, "TEXT_MODEL_EXTRA_BODY", {"reasoning_effort": "minimal"})
+ llm.call_llm_completion([{"role": "user", "content": "q"}])
+ kwargs = create.call_args.kwargs
+ # The SDK merges extra_body last, so the configured value is the one sent.
+ assert kwargs["reasoning_effort"] == "medium"
+ assert kwargs["extra_body"] == {"reasoning_effort": "minimal"}
+
+
+def test_invalid_setting_fails_the_request(monkeypatch, text_model):
+ create = _client(monkeypatch, "client")
+ monkeypatch.setattr(llm, "TEXT_MODEL_EXTRA_BODY_ERROR", "TEXT_MODEL_EXTRA_BODY is not valid JSON (x)")
+ with pytest.raises(ValueError, match="TEXT_MODEL_EXTRA_BODY is not valid JSON"):
+ llm.call_llm_completion([{"role": "user", "content": "q"}])
+ create.assert_not_called()
+
+
+def test_chat_on_the_text_model_uses_its_parameters(monkeypatch, text_model):
+ create = _client(monkeypatch, "client", "chat_client")
+ monkeypatch.setattr(llm, "TEXT_MODEL_EXTRA_BODY", {"reasoning": {"enabled": False}})
+ monkeypatch.setattr(llm, "CHAT_MODEL_EXTRA_BODY", {"ignored": True})
+ llm.call_chat_completion([{"role": "user", "content": "q"}])
+ assert create.call_args.kwargs["extra_body"] == {"reasoning": {"enabled": False}}
+
+
+def test_a_separate_chat_model_does_not_inherit_them(monkeypatch, text_model):
+ create = _client(monkeypatch, "client", "chat_client")
+ monkeypatch.setattr(llm, "CHAT_MODEL_NAME", "openai/gpt-4o")
+ monkeypatch.setattr(llm, "CHAT_MODEL_BASE_URL", "https://openrouter.ai/api/v1")
+ monkeypatch.setattr(llm, "TEXT_MODEL_EXTRA_BODY", {"chat_template_kwargs": {"enable_thinking": False}})
+ monkeypatch.setattr(llm, "CHAT_MODEL_EXTRA_BODY", {})
+ llm.call_chat_completion([{"role": "user", "content": "q"}])
+ assert "extra_body" not in create.call_args.kwargs
+
+ monkeypatch.setattr(llm, "CHAT_MODEL_EXTRA_BODY", {"reasoning": {"effort": "low"}})
+ llm.call_chat_completion([{"role": "user", "content": "q"}])
+ assert create.call_args.kwargs["extra_body"] == {"reasoning": {"effort": "low"}}
+
+
+def test_a_rejected_request_names_the_setting(monkeypatch, text_model, caplog):
+ response = httpx.Response(400, request=httpx.Request("POST", "http://vllm:8000/v1/chat/completions"))
+ error = openai.BadRequestError("unknown field", response=response, body=None)
+ _client(monkeypatch, "client", side_effect=error)
+ monkeypatch.setattr(llm, "TEXT_MODEL_EXTRA_BODY", {"reasoning": {"effort": "low"}})
+ with pytest.raises(openai.BadRequestError):
+ llm.call_llm_completion([{"role": "user", "content": "q"}])
+ assert "TEXT_MODEL_EXTRA_BODY adds reasoning" in caplog.text
+
+
+def test_incognito_requests_use_the_shared_helpers():
+ """Incognito title, summary and chat go through call_llm_completion and
+ call_chat_completion, so they get the GPT-5 handling and these settings."""
+ import ast, os
+ root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ for path in ("src/tasks/processing.py", "src/api/recordings.py"):
+ tree = ast.parse(open(os.path.join(root, path), encoding="utf-8").read())
+ direct = [n.lineno for n in ast.walk(tree) if isinstance(n, ast.Attribute) and n.attr == "create"
+ and isinstance(n.value, ast.Attribute) and n.value.attr == "completions"]
+ assert direct == [], f"{path} calls the client directly at lines {direct}"
diff --git a/tests/test_llm_temperatures.py b/tests/test_llm_temperatures.py
index d4bf9915..a6483ed5 100644
--- a/tests/test_llm_temperatures.py
+++ b/tests/test_llm_temperatures.py
@@ -142,7 +142,7 @@ def test_incognito_title_and_summary_use_the_resolved_values(ctx):
fake_client = MagicMock()
fake_client.chat.completions.create.side_effect = fake
- with patch.object(processing, 'client', fake_client):
+ with patch.object(processing, 'client', fake_client), patch('src.services.llm.client', fake_client):
processing._generate_incognito_title('Some transcript text about budgets.')
processing.generate_incognito_summary('Some transcript text about budgets.')
assert seen == [0.15, 0.0]
diff --git a/tests/test_title_prompt.py b/tests/test_title_prompt.py
index c5b89413..793de0e2 100644
--- a/tests/test_title_prompt.py
+++ b/tests/test_title_prompt.py
@@ -201,7 +201,7 @@ def test_incognito_titles_use_the_user_level(ctx):
fake_client = MagicMock()
fake_client.chat.completions.create.side_effect = fake_create
- with patch("src.tasks.processing.client", new=fake_client):
+ with patch("src.tasks.processing.client", new=fake_client), patch("src.services.llm.client", new=fake_client):
processing._generate_incognito_title(TRANSCRIPT, user=user)
assert '- Start with the date' in calls[-1][1]["content"]