A platform for community discussion. Free, open, simple.
FEATURE: Support OpenAI GPT-5.6 models (#41832)
Same1caf1d1d3d1
diff --git a/plugins/discourse-ai/app/models/llm_model.rb b/plugins/discourse-ai/app/models/llm_model.rbindex d9c4d56fd1e..a916e34078c 100644--- a/plugins/discourse-ai/app/models/llm_model.rb+++ b/plugins/discourse-ai/app/models/llm_model.rb@@ -9,6 +9,8 @@ class LlmModel < ActiveRecord::BaseBEDROCK_PROVIDER_NAME = "aws_bedrock"BEDROCK_CONVERSE_PROVIDER_NAME = "aws_bedrock_converse"GOOGLE_VERTEX_AI_PROVIDER_NAME = "google_vertex_ai"+ OPEN_AI_PROVIDER_NAME = "open_ai"+ OPEN_AI_REASONING_MODES = %w[standard pro].freeze# Interpolated into the Vertex AI hostname/path — must stay strict to avoid# sending environment credentials to an attacker-controlled host.GOOGLE_VERTEX_AI_REGION_FORMAT = /\A[a-z](?:[a-z0-9-]*[a-z0-9])?\z/@@ -241,16 +243,22 @@ class LlmModel < ActiveRecord::Basedisable_native_tools: :checkbox,reasoning_effort: {type: :enum,- values: %w[default none minimal low medium high xhigh],+ values: %w[default none minimal low medium high xhigh max],+ default: "default",+ },+ reasoning_mode: {+ type: :enum,+ values: ["default", *OPEN_AI_REASONING_MODES],default: "default",+ tooltip: "discourse_ai.llms.provider_field_hints.reasoning_mode",},disable_temperature: {type: :checkbox,- hidden_if: :reasoning_effort,+ hidden_if: %i[reasoning_effort reasoning_mode],},disable_top_p: {type: :checkbox,- hidden_if: :reasoning_effort,+ hidden_if: %i[reasoning_effort reasoning_mode],},disable_streaming: :checkbox,service_tier: {@@ -330,8 +338,9 @@ class LlmModel < ActiveRecord::Basedisable_native_tools: :checkbox,reasoning_effort: {type: :enum,- values: %w[default none minimal low medium high xhigh],+ values: %w[default none minimal low medium high xhigh max],default: "default",+ tooltip: "discourse_ai.llms.provider_field_hints.azure_reasoning_effort",},disable_temperature: {type: :checkbox,@@ -615,7 +624,12 @@ class LlmModel < ActiveRecord::Baseenddef required_provider_params- if provider == BEDROCK_PROVIDER_NAME+ reasoning_mode = lookup_custom_param("reasoning_mode")+ if provider == OPEN_AI_PROVIDER_NAME && reasoning_mode == "pro"+ if !url.to_s.include?("/v1/responses")+ errors.add(:base, I18n.t("discourse_ai.llm_models.reasoning_mode_requirements"))+ end+ elsif provider == BEDROCK_PROVIDER_NAMEif lookup_custom_param("region").blank?errors.add(:base, I18n.t("discourse_ai.llm_models.missing_provider_param", param: "region"))enddiff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.ymlindex 751f5947071..7128b9272ab 100644--- a/plugins/discourse-ai/config/locales/client.en.yml+++ b/plugins/discourse-ai/config/locales/client.en.yml@@ -988,9 +988,9 @@ en:anthropic-claude-haiku-4-5: "Fast and cost-effective"google-gemini-3-1-pro: "Google's most intelligent model"google-gemini-3-flash: "Fast and cost-efficient with multimodal reasoning"- open_ai-gpt-5-5: "OpenAI's most capable model with extended context"- open_ai-gpt-5-4: "OpenAI's flagship model, well suited for problem solving across domains"- open_ai-gpt-5-4-nano: "Fastest, most cost-effective GPT-5 model"+ open_ai-gpt-5-6-sol: "OpenAI's frontier model for complex professional work"+ open_ai-gpt-5-6-terra: "Balances intelligence and cost for demanding workloads"+ open_ai-gpt-5-6-luna: "Optimized for cost-sensitive, high-volume workloads"open_router-moonshotai-kimi-k2-6: "Moonshot's multimodal model with vision capabilities"open_router-deepseek-deepseek-v4-flash: "DeepSeek's latest high-performance model with 1M context"open_router-minimax-minimax-m2-7: "MiniMax's model with large context"@@ -1067,6 +1067,7 @@ en:provider_quantizations: "Order of provider quantizations (comma delimited list eg: fp16,fp8)"disable_streaming: "Disable streaming completions (convert streaming to non streaming requests)"reasoning_effort: "Reasoning effort (only applicable to reasoning models)"+ reasoning_mode: "Reasoning mode"service_tier: "Service tier (flex = lower cost/higher latency, priority = faster processing)"reasoning_parser: "vLLM reasoning parser"thinking_override: "Thinking override"@@ -1086,6 +1087,8 @@ en:effort: "Effort level"provider_field_hints:+ reasoning_mode: "Standard mode uses the provider default. Pro mode requires the Responses API and support from the selected model, and increases latency and token usage."+ azure_reasoning_effort: "Available effort levels depend on the model deployed in Azure. Unsupported values are rejected by Azure."reasoning_parser: "Must match the vLLM server --reasoning-parser setting. Discourse cannot switch parsers per request; it uses this to shape request options."thinking_override: "Optionally force supported vLLM chat templates to enable or disable thinking for each request. Unsupported parsers keep the server default."reasoning_effort: "Sends vLLM's reasoning_effort request option for parsers that support it."diff --git a/plugins/discourse-ai/config/locales/server.en.yml b/plugins/discourse-ai/config/locales/server.en.ymlindex 57467712443..183e4a79310 100644--- a/plugins/discourse-ai/config/locales/server.en.yml+++ b/plugins/discourse-ai/config/locales/server.en.yml@@ -1058,6 +1058,7 @@ en:llm_models:missing_provider_param: "%{param} can't be blank"invalid_provider_param: "%{param} has an invalid format"+ reasoning_mode_requirements: "Pro reasoning mode requires the Responses API"secret_required: "A credential must be selected"secret_not_found: "The selected credential does not exist"bedrock_invalid_url: "Please complete all the fields to use this model."diff --git a/plugins/discourse-ai/lib/completions/endpoints/open_ai_responses.rb b/plugins/discourse-ai/lib/completions/endpoints/open_ai_responses.rbindex b8b86840b4e..7dfaf1f6539 100644--- a/plugins/discourse-ai/lib/completions/endpoints/open_ai_responses.rb+++ b/plugins/discourse-ai/lib/completions/endpoints/open_ai_responses.rb@@ -22,6 +22,7 @@ module DiscourseAireasoning_payload = { summary: "auto" }reasoning_payload[:effort] = reasoning_effort if reasoning_effort+ reasoning_payload[:mode] = reasoning_mode if reasoning_modepayload.merge!(reasoning: reasoning_payload)payload[:service_tier] = service_tier if service_tierdiff --git a/plugins/discourse-ai/lib/completions/endpoints/open_ai_shared.rb b/plugins/discourse-ai/lib/completions/endpoints/open_ai_shared.rbindex 4aa24f5e046..a7e735179ab 100644--- a/plugins/discourse-ai/lib/completions/endpoints/open_ai_shared.rb+++ b/plugins/discourse-ai/lib/completions/endpoints/open_ai_shared.rb@@ -4,12 +4,27 @@ module DiscourseAimodule Completionsmodule Endpointsmodule OpenAiShared- OPEN_AI_REASONING_EFFORTS = %w[none minimal low medium high xhigh].freeze+ OPEN_AI_REASONING_EFFORTS = %w[none minimal low medium high xhigh max].freeze+ # Unknown and newer models receive max unchanged; only documented xhigh-ceiling+ # models are downgraded.+ OPEN_AI_MAX_TO_XHIGH_MODELS = %w[+ gpt-5.1-codex-max+ gpt-5.2+ gpt-5.2-pro+ gpt-5.2-codex+ gpt-5.3-codex+ gpt-5.4+ gpt-5.4-mini+ gpt-5.4-nano+ gpt-5.4-pro+ gpt-5.5+ gpt-5.5-pro+ ].freeze+ OPEN_AI_MODEL_SNAPSHOT_SUFFIX = /-\d{4}-\d{2}-\d{2}\z/OPEN_AI_REASONING_OUTPUT_RESERVATION = 25_000- # "minimal" isn't a distinct tier on some OpenAI reasoning models (e.g.- # gpt-5.5 rejects it outright) — collapse it into "low", same as vLLM's- # own reasoning effort scale already does.- OPEN_AI_EFFORT_ALIASES = { "max" => "xhigh", "minimal" => "low" }.freeze+ # "minimal" isn't a distinct tier on every OpenAI reasoning model and can+ # be rejected outright, so collapse it into "low".+ OPEN_AI_EFFORT_ALIASES = { "minimal" => "low" }.freezedef default_options{ model: llm_model.name }@@ -67,9 +82,13 @@ module DiscourseAi)effort ||= legacy_reasoning_effort- return DiscourseAi::Completions::ThinkingConfig.disabled if effort.blank?+ if effort.blank?+ return default_reasoning_mode_thinking_config(model_params) if reasoning_mode+ return DiscourseAi::Completions::ThinkingConfig.disabled+ endprovider_effort = OPEN_AI_EFFORT_ALIASES[effort] || effort+ provider_effort = "xhigh" if provider_effort == "max" && max_effort_maps_to_xhigh?if !OPEN_AI_REASONING_EFFORTS.include?(provider_effort)return DiscourseAi::Completions::ThinkingConfig.unsupported(canonical_effort: effort)end@@ -103,6 +122,36 @@ module DiscourseAithinking_config&.provider_effortend+ def reasoning_mode+ return @reasoning_mode if defined?(@reasoning_mode)++ @reasoning_mode = llm_model.lookup_custom_param("reasoning_mode")+ if !LlmModel::OPEN_AI_REASONING_MODES.include?(@reasoning_mode) ||+ !supports_reasoning_mode?+ @reasoning_mode = nil+ end+ @reasoning_mode+ end++ def default_reasoning_mode_thinking_config(model_params)+ DiscourseAi::Completions::ThinkingConfig.new(+ enabled: true,+ reserved_output_tokens: open_ai_reasoning_output_reservation(model_params, "medium"),+ strip_temperature: true,+ strip_top_p: true,+ )+ end++ def supports_reasoning_mode?+ llm_model.provider == LlmModel::OPEN_AI_PROVIDER_NAME &&+ llm_model.url.to_s.include?("/v1/responses")+ end++ def max_effort_maps_to_xhigh?+ model_name = llm_model.name.to_s.sub(OPEN_AI_MODEL_SNAPSHOT_SUFFIX, "")+ OPEN_AI_MAX_TO_XHIGH_MODELS.include?(model_name)+ end+def legacy_reasoning_effortreturn @legacy_reasoning_effort if defined?(@legacy_reasoning_effort)@legacy_reasoning_effort = llm_model.lookup_custom_param("reasoning_effort")@@ -153,6 +202,7 @@ module DiscourseAilog.request_tokens = processor.prompt_tokens if processor.prompt_tokenslog.response_tokens = processor.completion_tokens if processor.completion_tokenslog.cache_read_tokens = processor.cache_read_tokens if processor.cache_read_tokens+ log.cache_write_tokens = processor.cache_write_tokens if processor.cache_write_tokensenddef decode(response_raw)diff --git a/plugins/discourse-ai/lib/completions/llm_presets.rb b/plugins/discourse-ai/lib/completions/llm_presets.rbindex 6bef911b567..15806bfd483 100644--- a/plugins/discourse-ai/lib/completions/llm_presets.rb+++ b/plugins/discourse-ai/lib/completions/llm_presets.rb@@ -177,35 +177,38 @@ module DiscourseAiid: "open_ai",models: [model(- name: "gpt-5.5",+ name: "gpt-5.6-sol",tokens: 1_050_000,- display_name: "GPT-5.5",+ display_name: "GPT-5.6 Sol",max_output_tokens: 128_000,input_cost: 5.0,cached_input_cost: 0.50,+ cache_write_cost: 6.25,output_cost: 30.0,vision_enabled: true,endpoint: "https://api.openai.com/v1/responses",),model(- name: "gpt-5.4",- tokens: 400_000,- display_name: "GPT-5.4",+ name: "gpt-5.6-terra",+ tokens: 1_050_000,+ display_name: "GPT-5.6 Terra",max_output_tokens: 128_000,input_cost: 2.50,cached_input_cost: 0.25,+ cache_write_cost: 3.125,output_cost: 15.0,vision_enabled: true,endpoint: "https://api.openai.com/v1/responses",),model(- name: "gpt-5.4-nano",- tokens: 400_000,- display_name: "GPT-5.4 Nano",+ name: "gpt-5.6-luna",+ tokens: 1_050_000,+ display_name: "GPT-5.6 Luna",max_output_tokens: 128_000,- input_cost: 0.20,- cached_input_cost: 0.02,- output_cost: 1.25,+ input_cost: 1.0,+ cached_input_cost: 0.10,+ cache_write_cost: 1.25,+ output_cost: 6.0,vision_enabled: true,endpoint: "https://api.openai.com/v1/responses",),diff --git a/plugins/discourse-ai/lib/completions/open_ai_message_processor.rb b/plugins/discourse-ai/lib/completions/open_ai_message_processor.rbindex 59fa91f6b25..7dc6083d8a9 100644--- a/plugins/discourse-ai/lib/completions/open_ai_message_processor.rb+++ b/plugins/discourse-ai/lib/completions/open_ai_message_processor.rb@@ -1,7 +1,7 @@# frozen_string_literal: truemodule DiscourseAi::Completionsclass OpenAiMessageProcessor- attr_reader :prompt_tokens, :completion_tokens, :cache_read_tokens+ attr_reader :prompt_tokens, :completion_tokens, :cache_read_tokens, :cache_write_tokensdef initialize(partial_tool_calls: false)@tool = nil@@ -9,6 +9,7 @@ module DiscourseAi::Completions@prompt_tokens = nil@completion_tokens = nil@cache_read_tokens = nil+ @cache_write_tokens = nil@partial_tool_calls = partial_tool_callsend@@ -125,14 +126,17 @@ module DiscourseAi::Completionsusage = json.dig(:usage)return if !usage- cached_tokens = usage.dig(:prompt_tokens_details, :cached_tokens).to_i+ token_details = usage[:prompt_tokens_details] || {}+ cached_tokens = token_details[:cached_tokens].to_i+ cache_write_tokens = token_details[:cache_write_tokens].to_iprompt_tokens = usage[:prompt_tokens].to_icompletion_tokens = usage[:completion_tokens].to_i- @prompt_tokens = prompt_tokens - cached_tokens+ @prompt_tokens = prompt_tokens - cached_tokens - cache_write_tokens@completion_tokens = completion_tokens if completion_tokens.positive?@cache_read_tokens = cached_tokens+ @cache_write_tokens = cache_write_tokensendendenddiff --git a/plugins/discourse-ai/lib/completions/open_ai_responses_message_processor.rb b/plugins/discourse-ai/lib/completions/open_ai_responses_message_processor.rbindex 419a046380f..6c05692fac8 100644--- a/plugins/discourse-ai/lib/completions/open_ai_responses_message_processor.rb+++ b/plugins/discourse-ai/lib/completions/open_ai_responses_message_processor.rb@@ -3,7 +3,7 @@ module DiscourseAi::Completionsclass OpenAiResponsesMessageProcessorPROVIDER_KEY = :open_ai_responses- attr_reader :prompt_tokens, :completion_tokens, :cache_read_tokens+ attr_reader :prompt_tokens, :completion_tokens, :cache_read_tokens, :cache_write_tokensdef initialize(partial_tool_calls: false, output_thinking: false)@tool = nil # currently streaming ToolCall@@ -11,6 +11,7 @@ module DiscourseAi::Completions@prompt_tokens = nil@completion_tokens = nil@cache_read_tokens = nil+ @cache_write_tokens = nil@partial_tool_calls = partial_tool_calls@streaming_parser = nil # JsonStreamingTracker, if used@has_new_data = false@@ -281,14 +282,17 @@ module DiscourseAi::Completionsenddef update_usage(json)- usage = json.dig(:response, :usage)+ usage = json.dig(:response, :usage) || json[:usage]return if !usage- cached_tokens = usage.dig(:input_tokens_details, :cached_tokens).to_i+ token_details = usage[:input_tokens_details] || {}+ cached_tokens = token_details[:cached_tokens].to_i+ cache_write_tokens = token_details[:cache_write_tokens].to_i- @prompt_tokens ||= usage[:input_tokens] - cached_tokens+ @prompt_tokens ||= usage[:input_tokens] - cached_tokens - cache_write_tokens@completion_tokens ||= usage[:output_tokens]@cache_read_tokens ||= cached_tokens+ @cache_write_tokens ||= cache_write_tokensenddef build_partial_reasoning_delta(json, prefix: nil)diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_responses_api_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_responses_api_spec.rbindex 705c353f96a..c250dbc3a56 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_responses_api_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_responses_api_spec.rb@@ -343,6 +343,40 @@ data: {"type":"response.reasoning_summary_part.added","sequence_number":3,"item_)end+ it "records cache-write tokens and configured cost for non-streaming responses" do+ model.update!(+ name: "gpt-5.6-luna",+ input_cost: 1.0,+ cached_input_cost: 0.1,+ cache_write_cost: 1.25,+ output_cost: 6.0,+ )+ stub_request(:post, "https://api.openai.com/v1/responses").to_return(+ status: 200,+ body: {+ output: [{ type: "message", content: [{ type: "output_text", text: "ok" }] }],+ usage: {+ input_tokens: 2_006,+ output_tokens: 300,+ input_tokens_details: {+ cached_tokens: 1_920,+ cache_write_tokens: 64,+ },+ },+ }.to_json,+ )++ result = model.to_llm.generate("hello", user: Discourse.system_user)++ expect(result).to eq("ok")+ log = AiApiAuditLog.last+ expect(log.request_tokens).to eq(22)+ expect(log.response_tokens).to eq(300)+ expect(log.cache_read_tokens).to eq(1_920)+ expect(log.cache_write_tokens).to eq(64)+ expect(log.estimated_cost).to eq(BigDecimal("0.002094"))+ end+it "accepts xhigh as reasoning_effort for responses API" domodel.update!(provider_params: { reasoning_effort: "xhigh" })@@ -368,6 +402,118 @@ data: {"type":"response.reasoning_summary_part.added","sequence_number":3,"item_expect(parsed_body[:reasoning]).to include(effort: "xhigh", summary: "auto")end+ it "sends native max effort and pro mode for GPT-5.6" do+ model.update!(+ name: "gpt-5.6-sol",+ provider_params: {+ reasoning_effort: "max",+ reasoning_mode: "pro",+ },+ )++ parsed_body = nil+ stub_request(:post, "https://api.openai.com/v1/responses").with(+ body:+ proc do |req_body|+ parsed_body = JSON.parse(req_body, symbolize_names: true)+ true+ end,+ ).to_return(status: 200, body: { output: [] }.to_json)++ prompt =+ DiscourseAi::Completions::Prompt.new(+ "You are a bot",+ messages: [type: :user, content: "hello"],+ )+ dialect = DiscourseAi::Completions::Dialects::OpenAiResponses.new(prompt, model)++ endpoint.perform_completion!(dialect, Discourse.system_user, { temperature: 0.7, top_p: 0.9 })++ expect(parsed_body[:reasoning]).to eq(summary: "auto", effort: "max", mode: "pro")+ expect(parsed_body).not_to have_key(:temperature)+ expect(parsed_body).not_to have_key(:top_p)+ end++ it "uses the provider's default effort for pro mode" do+ model.update!(name: "gpt-5.6-sol", provider_params: { reasoning_mode: "pro" })++ parsed_body = nil+ stub_request(:post, "https://api.openai.com/v1/responses").with(+ body:+ proc do |req_body|+ parsed_body = JSON.parse(req_body, symbolize_names: true)+ true+ end,+ ).to_return(status: 200, body: { output: [] }.to_json)++ prompt =+ DiscourseAi::Completions::Prompt.new(+ "You are a bot",+ messages: [type: :user, content: "hello"],+ )+ dialect = DiscourseAi::Completions::Dialects::OpenAiResponses.new(prompt, model)++ expect(endpoint.prepare_model_params({})[:reserved_output_tokens]).to eq(25_000)+ endpoint.perform_completion!(dialect, Discourse.system_user, { temperature: 0.7, top_p: 0.9 })++ expect(parsed_body[:reasoning]).to eq(summary: "auto", mode: "pro")+ expect(parsed_body).not_to have_key(:temperature)+ expect(parsed_body).not_to have_key(:top_p)+ end++ it "sends standard reasoning mode for custom model names" do+ model.update!(+ name: "future-reasoning-deployment",+ provider_params: {+ reasoning_mode: "standard",+ },+ )++ parsed_body = nil+ stub_request(:post, "https://api.openai.com/v1/responses").with(+ body:+ proc do |req_body|+ parsed_body = JSON.parse(req_body, symbolize_names: true)+ true+ end,+ ).to_return(status: 200, body: { output: [] }.to_json)++ prompt =+ DiscourseAi::Completions::Prompt.new(+ "You are a bot",+ messages: [type: :user, content: "hello"],+ )+ dialect = DiscourseAi::Completions::Dialects::OpenAiResponses.new(prompt, model)++ endpoint.perform_completion!(dialect, Discourse.system_user)++ expect(parsed_body[:reasoning]).to eq(summary: "auto", mode: "standard")+ end++ it "omits unsupported reasoning modes" do+ model.update!(provider_params: { reasoning_mode: "unsupported" })++ parsed_body = nil+ stub_request(:post, "https://api.openai.com/v1/responses").with(+ body:+ proc do |req_body|+ parsed_body = JSON.parse(req_body, symbolize_names: true)+ true+ end,+ ).to_return(status: 200, body: { output: [] }.to_json)++ prompt =+ DiscourseAi::Completions::Prompt.new(+ "You are a bot",+ messages: [type: :user, content: "hello"],+ )+ dialect = DiscourseAi::Completions::Dialects::OpenAiResponses.new(prompt, model)++ endpoint.perform_completion!(dialect, Discourse.system_user)++ expect(parsed_body[:reasoning]).to eq(summary: "auto")+ end+it "accepts none as reasoning_effort for responses API" domodel.update!(provider_params: { reasoning_effort: "none" })diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rbindex cc545b4f7a7..ff1b924fe4f 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb@@ -1197,8 +1197,8 @@ TEXTexpect(parsed_body).not_to have_key(:top_p)end- it "uses per-call thinking_effort before model reasoning_effort" do- model.update!(provider_params: { reasoning_effort: "low" })+ it "uses per-call thinking effort and maps max to xhigh for allowlisted models" do+ model.update!(name: "gpt-5.5-2026-04-24", provider_params: { reasoning_effort: "low" })parsed_body = nilstub_request(:post, "https://api.openai.com/v1/chat/completions").with(@@ -1215,6 +1215,65 @@ TEXTexpect(parsed_body).not_to have_key(:temperature)end+ it "uses native max effort for GPT-5.6" do+ model.update!(name: "gpt-5.6-sol")++ parsed_body = nil+ stub_request(:post, "https://api.openai.com/v1/chat/completions").with(+ body:+ proc do |req_body|+ parsed_body = JSON.parse(req_body, symbolize_names: true)+ true+ end,+ ).to_return(status: 200, body: { choices: [{ message: { content: "test" } }] }.to_json)++ endpoint.perform_completion!(dialect, user, { thinking_effort: "max" })++ expect(parsed_body[:reasoning_effort]).to eq("max")+ end++ it "uses native max effort for future OpenAI models by default" do+ model.update!(name: "gpt-5.7")++ parsed_body = nil+ stub_request(:post, "https://api.openai.com/v1/chat/completions").with(+ body:+ proc do |req_body|+ parsed_body = JSON.parse(req_body, symbolize_names: true)+ true+ end,+ ).to_return(status: 200, body: { choices: [{ message: { content: "test" } }] }.to_json)++ endpoint.perform_completion!(dialect, user, { thinking_effort: "max" })++ expect(parsed_body[:reasoning_effort]).to eq("max")+ end++ it "passes max through for Azure deployments with opaque names" do+ azure_url = "https://test.openai.azure.com/openai/v1/chat/completions"+ model.update!(+ provider: "azure",+ name: "production-deployment",+ url: azure_url,+ provider_params: {+ reasoning_effort: "max",+ },+ )++ parsed_body = nil+ stub_request(:post, azure_url).with(+ body:+ proc do |req_body|+ parsed_body = JSON.parse(req_body, symbolize_names: true)+ true+ end,+ ).to_return(status: 200, body: { choices: [{ message: { content: "test" } }] }.to_json)++ endpoint.perform_completion!(dialect, user)++ expect(parsed_body[:reasoning_effort]).to eq("max")+ end+it "reserves OpenAI recommended output room for reasoning when no token cap is configured" doprepared_params = endpoint.prepare_model_params(thinking_effort: "high")@@ -1235,6 +1294,24 @@ TEXTexpect(prepared_params).not_to have_key(:reserved_output_tokens)end+ it "treats standard reasoning mode as a no-op for Chat Completions" do+ model.update!(provider_params: { reasoning_mode: "standard" })++ parsed_body = nil+ stub_request(:post, "https://api.openai.com/v1/chat/completions").with(+ body:+ proc do |req_body|+ parsed_body = JSON.parse(req_body, symbolize_names: true)+ true+ end,+ ).to_return(status: 200, body: { choices: [{ message: { content: "test" } }] }.to_json)++ endpoint.perform_completion!(dialect, user)++ expect(parsed_body).not_to have_key(:reasoning)+ expect(parsed_body).not_to have_key(:reasoning_effort)+ end+it "omits reasoning parameters when not configured" doparsed_body = nilstub_request(:post, "https://api.openai.com/v1/chat/completions").with(diff --git a/plugins/discourse-ai/spec/lib/completions/llm_presets_spec.rb b/plugins/discourse-ai/spec/lib/completions/llm_presets_spec.rbindex 08b3b83a53d..c2dd337f926 100644--- a/plugins/discourse-ai/spec/lib/completions/llm_presets_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/llm_presets_spec.rb@@ -30,6 +30,51 @@ RSpec.describe DiscourseAi::Completions::LlmPresets doexpect(model[:provider_params]).to include(region: "global")end+ it "includes the current GPT-5.6 family with pricing and capabilities" do+ preset = described_class.find_provider("open_ai")++ expect(preset[:models]).to eq(+ [+ {+ name: "gpt-5.6-sol",+ tokens: 1_050_000,+ display_name: "GPT-5.6 Sol",+ max_output_tokens: 128_000,+ input_cost: 5.0,+ cached_input_cost: 0.50,+ cache_write_cost: 6.25,+ output_cost: 30.0,+ vision_enabled: true,+ endpoint: "https://api.openai.com/v1/responses",+ },+ {+ name: "gpt-5.6-terra",+ tokens: 1_050_000,+ display_name: "GPT-5.6 Terra",+ max_output_tokens: 128_000,+ input_cost: 2.50,+ cached_input_cost: 0.25,+ cache_write_cost: 3.125,+ output_cost: 15.0,+ vision_enabled: true,+ endpoint: "https://api.openai.com/v1/responses",+ },+ {+ name: "gpt-5.6-luna",+ tokens: 1_050_000,+ display_name: "GPT-5.6 Luna",+ max_output_tokens: 128_000,+ input_cost: 1.0,+ cached_input_cost: 0.10,+ cache_write_cost: 1.25,+ output_cost: 6.0,+ vision_enabled: true,+ endpoint: "https://api.openai.com/v1/responses",+ },+ ],+ )+ end+it "marks every Anthropic model known to require adaptive-only thinking" do%w[claude-opus-4-7 claude-opus-4-8 claude-sonnet-5].each do |name|model = described_class.find_model("anthropic", name)diff --git a/plugins/discourse-ai/spec/lib/completions/open_ai_message_processor_spec.rb b/plugins/discourse-ai/spec/lib/completions/open_ai_message_processor_spec.rbindex b6995a42fdc..9470827434d 100644--- a/plugins/discourse-ai/spec/lib/completions/open_ai_message_processor_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/open_ai_message_processor_spec.rb@@ -144,4 +144,25 @@ RSpec.describe DiscourseAi::Completions::OpenAiMessageProcessor doprocessor.process_streamed_message(chunk(delta: {}, finish_reason: "tool_calls"))}.to raise_error(JSON::ParserError)end++ it "separates uncached, cache-read, and cache-write input tokens" do+ processor = described_class.new++ processor.process_message(+ choices: [],+ usage: {+ prompt_tokens: 2_006,+ completion_tokens: 300,+ prompt_tokens_details: {+ cached_tokens: 1_920,+ cache_write_tokens: 64,+ },+ },+ )++ expect(processor.prompt_tokens).to eq(22)+ expect(processor.completion_tokens).to eq(300)+ expect(processor.cache_read_tokens).to eq(1_920)+ expect(processor.cache_write_tokens).to eq(64)+ endenddiff --git a/plugins/discourse-ai/spec/lib/completions/open_ai_responses_message_processor_spec.rb b/plugins/discourse-ai/spec/lib/completions/open_ai_responses_message_processor_spec.rbindex cc5ab62f1cc..cec6088671a 100644--- a/plugins/discourse-ai/spec/lib/completions/open_ai_responses_message_processor_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/open_ai_responses_message_processor_spec.rb@@ -86,4 +86,27 @@ RSpec.describe DiscourseAi::Completions::OpenAiResponsesMessageProcessor doexpect(result.last).to eq("HN summary")endend++ describe "usage" do+ it "separates uncached, cache-read, and cache-write input tokens" do+ processor = described_class.new++ processor.process_message(+ output: [],+ usage: {+ input_tokens: 2_006,+ output_tokens: 300,+ input_tokens_details: {+ cached_tokens: 1_920,+ cache_write_tokens: 64,+ },+ },+ )++ expect(processor.prompt_tokens).to eq(22)+ expect(processor.completion_tokens).to eq(300)+ expect(processor.cache_read_tokens).to eq(1_920)+ expect(processor.cache_write_tokens).to eq(64)+ end+ endenddiff --git a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rbindex 1f2854ccaf4..b0e0f549eba 100644--- a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb@@ -59,6 +59,31 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController doexpect(capabilities.dig("anthropic", "requires_configured_url")).to eq(true)end+ it "includes OpenAI reasoning controls metadata" do+ get "/admin/plugins/discourse-ai/ai-llms.json"+ expect(response).to be_successful++ open_ai_params = response.parsed_body.dig("meta", "provider_params", "open_ai")+ expect(open_ai_params["reasoning_effort"]).to include(+ "type" => "enum",+ "values" => %w[default none minimal low medium high xhigh max],+ "default" => "default",+ )+ expect(open_ai_params["reasoning_mode"]).to include(+ "type" => "enum",+ "values" => %w[default standard pro],+ "default" => "default",+ )++ azure_params = response.parsed_body.dig("meta", "provider_params", "azure")+ expect(azure_params["reasoning_effort"]).to include(+ "type" => "enum",+ "values" => %w[default none minimal low medium high xhigh max],+ "default" => "default",+ )+ expect(azure_params).not_to have_key("reasoning_mode")+ end+it "includes vLLM reasoning controls metadata" doget "/admin/plugins/discourse-ai/ai-llms.json"expect(response).to be_successful@@ -274,6 +299,30 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController do)end+ it "stores reasoning configuration for custom model names" do+ provider_params = { reasoning_effort: "max", reasoning_mode: "pro" }+ attrs =+ valid_attrs.merge(+ name: "future-reasoning-deployment",+ url: "https://api.openai.com/v1/responses",+ provider_params: provider_params,+ )++ post "/admin/plugins/discourse-ai/ai-llms.json", params: { ai_llm: attrs }++ expect(response.status).to eq(201)+ expect(LlmModel.last.provider_params).to eq(provider_params.stringify_keys)+ end++ it "allows standard reasoning mode with Chat Completions" do+ attrs = valid_attrs.merge(provider_params: { reasoning_mode: "standard" })++ post "/admin/plugins/discourse-ai/ai-llms.json", params: { ai_llm: attrs }++ expect(response.status).to eq(201)+ expect(LlmModel.last.provider_params["reasoning_mode"]).to eq("standard")+ end+it "does not store nested hash values in provider_params" doprovider_params = { organization: { nested: "injected_value" } }@@ -302,6 +351,17 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController doendcontext "with invalid attributes" do+ it "rejects pro reasoning mode without a Responses API configuration" do+ attrs = valid_attrs.merge(provider_params: { reasoning_mode: "pro" })++ post "/admin/plugins/discourse-ai/ai-llms.json", params: { ai_llm: attrs }++ expect(response.status).to eq(422)+ expect(response.parsed_body["errors"]).to contain_exactly(+ I18n.t("discourse_ai.llm_models.reasoning_mode_requirements"),+ )+ end+it "doesn't create a model" dopost "/admin/plugins/discourse-ai/ai-llms.json",params: {