Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: add Google Vertex AI LLM provider (#41350)

Evan Tobinfc49238104b2
diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs
index af610fa1d53..c5cecddb1d9 100644
--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs
+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs
@@ -192,7 +192,9 @@ export default class AiLlmEditorForm extends Component {
@action
canEditURL(provider) {
- return provider !== "aws_bedrock";
+ const capabilities =
+ this.args.llms.resultSetMeta.provider_capabilities?.[provider];
+ return capabilities?.requires_configured_url ?? true;
}
@action
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llms_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llms_controller.rb
index c612ebdba10..324cead18a1 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llms_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llms_controller.rb
@@ -20,6 +20,7 @@ module DiscourseAi
).as_json,
meta: {
provider_params: LlmModel.provider_params,
+ provider_capabilities: DiscourseAi::Completions::Llm.provider_capabilities,
presets: DiscourseAi::Completions::Llm.presets,
providers: DiscourseAi::Completions::Llm.provider_names,
tokenizers:
diff --git a/plugins/discourse-ai/app/models/llm_model.rb b/plugins/discourse-ai/app/models/llm_model.rb
index da1dbe106fa..d9c4d56fd1e 100644
--- a/plugins/discourse-ai/app/models/llm_model.rb
+++ b/plugins/discourse-ai/app/models/llm_model.rb
@@ -8,6 +8,11 @@ class LlmModel < ActiveRecord::Base
FIRST_BOT_USER_ID = -1200
BEDROCK_PROVIDER_NAME = "aws_bedrock"
BEDROCK_CONVERSE_PROVIDER_NAME = "aws_bedrock_converse"
+ GOOGLE_VERTEX_AI_PROVIDER_NAME = "google_vertex_ai"
+ # 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/
+ GOOGLE_VERTEX_AI_PROJECT_ID_FORMAT = /\A[a-z][a-z0-9-]{4,28}[a-z0-9]\z/
DEFAULT_ALLOWED_ATTACHMENT_TYPES = [].freeze
ATTACHMENT_TYPE_ALIASES = {
"markdown" => "md",
@@ -99,9 +104,7 @@ class LlmModel < ActiveRecord::Base
validates :display_name, presence: true, length: { maximum: 100 }
validates :tokenizer, presence: true, inclusion: DiscourseAi::Completions::Llm.tokenizer_names
validates :provider, presence: true, inclusion: DiscourseAi::Completions::Llm.provider_names
- validates :url,
- presence: true,
- unless: -> { provider.in?([BEDROCK_PROVIDER_NAME, BEDROCK_CONVERSE_PROVIDER_NAME]) }
+ validates :url, presence: true, if: -> { llm_endpoint&.requires_configured_url? != false }
validates :name, presence: true
validate :api_key_or_secret_present
validates :max_prompt_tokens, numericality: { greater_than: 0 }
@@ -301,6 +304,28 @@ class LlmModel < ActiveRecord::Base
default: "default",
},
},
+ google_vertex_ai: {
+ project_id: :text,
+ region: :text,
+ disable_native_tools: :checkbox,
+ enable_thinking: :checkbox,
+ thinking_level: {
+ type: :enum,
+ values: %w[default minimal low medium high],
+ default: "default",
+ depends_on: :enable_thinking,
+ },
+ thinking_tokens: {
+ type: :number,
+ depends_on: :enable_thinking,
+ hidden_if: :thinking_level,
+ },
+ disable_temperature: {
+ type: :checkbox,
+ hidden_if: :enable_thinking,
+ },
+ disable_top_p: :checkbox,
+ },
azure: {
disable_native_tools: :checkbox,
reasoning_effort: {
@@ -570,8 +595,9 @@ class LlmModel < ActiveRecord::Base
def api_key_or_secret_present
return if seeded?
- # Converse provider supports auto-resolved credentials (env vars, instance profile)
- return if provider == BEDROCK_CONVERSE_PROVIDER_NAME
+
+ return if llm_endpoint&.supports_environment_credentials?
+
if ai_secret_id.present?
unless AiSecret.exists?(ai_secret_id)
errors.add(:ai_secret_id, I18n.t("discourse_ai.llm_models.secret_not_found"))
@@ -582,6 +608,12 @@ class LlmModel < ActiveRecord::Base
errors.add(:base, I18n.t("discourse_ai.llm_models.secret_required"))
end
+ def llm_endpoint
+ DiscourseAi::Completions::Endpoints::Base.endpoint_for(self)
+ rescue DiscourseAi::Completions::Llm::UNKNOWN_MODEL
+ nil
+ end
+
def required_provider_params
if provider == BEDROCK_PROVIDER_NAME
if lookup_custom_param("region").blank?
@@ -596,6 +628,27 @@ class LlmModel < ActiveRecord::Base
errors.add(:base, I18n.t("discourse_ai.llm_models.missing_provider_param", param: "region"))
end
# access_key_id and role_arn are optional — SDK can auto-resolve credentials
+ elsif provider == GOOGLE_VERTEX_AI_PROVIDER_NAME
+ region = lookup_custom_param("region")
+ project_id = lookup_custom_param("project_id")
+
+ if region.blank?
+ errors.add(:base, I18n.t("discourse_ai.llm_models.missing_provider_param", param: "region"))
+ elsif !region.to_s.match?(GOOGLE_VERTEX_AI_REGION_FORMAT)
+ errors.add(:base, I18n.t("discourse_ai.llm_models.invalid_provider_param", param: "region"))
+ end
+
+ if project_id.blank?
+ errors.add(
+ :base,
+ I18n.t("discourse_ai.llm_models.missing_provider_param", param: "project_id"),
+ )
+ elsif !project_id.to_s.match?(GOOGLE_VERTEX_AI_PROJECT_ID_FORMAT)
+ errors.add(
+ :base,
+ I18n.t("discourse_ai.llm_models.invalid_provider_param", param: "project_id"),
+ )
+ end
end
end
end
diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.yml
index 5b17c8ac570..751f5947071 100644
--- a/plugins/discourse-ai/config/locales/client.en.yml
+++ b/plugins/discourse-ai/config/locales/client.en.yml
@@ -1042,6 +1042,7 @@ en:
cohere: "Cohere"
open_ai: "OpenAI"
google: "Google"
+ google_vertex_ai: "Google Vertex AI"
azure: "Azure"
ollama: "Ollama"
CDCK: "CDCK"
@@ -1055,7 +1056,8 @@ en:
access_key_id: "AWS Bedrock access key ID"
role_arn: "AWS Bedrock Role ARN"
inference_profile_arn: "AWS Bedrock application inference profile ARN"
- region: "AWS Bedrock region"
+ region: "Region"
+ project_id: "GCP Project ID"
organization: "Optional OpenAI organization ID"
disable_system_prompt: "Disable system message in prompts"
enable_native_tool: "Enable native tool support"
diff --git a/plugins/discourse-ai/config/locales/server.en.yml b/plugins/discourse-ai/config/locales/server.en.yml
index ed4696fa651..a6127cf95f8 100644
--- a/plugins/discourse-ai/config/locales/server.en.yml
+++ b/plugins/discourse-ai/config/locales/server.en.yml
@@ -1055,6 +1055,7 @@ en:
llm_models:
missing_provider_param: "%{param} can't be blank"
+ invalid_provider_param: "%{param} has an invalid format"
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/dialects/gemini.rb b/plugins/discourse-ai/lib/completions/dialects/gemini.rb
index 8c23c5f49b5..80967d8ed5d 100644
--- a/plugins/discourse-ai/lib/completions/dialects/gemini.rb
+++ b/plugins/discourse-ai/lib/completions/dialects/gemini.rb
@@ -6,7 +6,7 @@ module DiscourseAi
class Gemini < Dialect
class << self
def can_translate?(llm_model)
- llm_model.provider == "google"
+ llm_model.provider == "google" || llm_model.provider == "google_vertex_ai"
end
end
diff --git a/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock.rb b/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock.rb
index 8bb6d783131..9f602de490d 100644
--- a/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock.rb
+++ b/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock.rb
@@ -14,6 +14,10 @@ module DiscourseAi
llm_model.provider == "aws_bedrock"
end
+ def self.requires_configured_url?
+ false
+ end
+
def default_options(dialect)
options =
if dialect.is_a?(DiscourseAi::Completions::Dialects::Claude)
diff --git a/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock_converse.rb b/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock_converse.rb
index 73ea3481534..3c20ead5955 100644
--- a/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock_converse.rb
+++ b/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock_converse.rb
@@ -10,6 +10,14 @@ module DiscourseAi
llm_model.provider == "aws_bedrock_converse"
end
+ def self.supports_environment_credentials?
+ true
+ end
+
+ def self.requires_configured_url?
+ false
+ end
+
def provider_id
AiApiAuditLog::Provider::BedrockConverse
end
diff --git a/plugins/discourse-ai/lib/completions/endpoints/base.rb b/plugins/discourse-ai/lib/completions/endpoints/base.rb
index 638d90c2a1f..f3b5d1bd057 100644
--- a/plugins/discourse-ai/lib/completions/endpoints/base.rb
+++ b/plugins/discourse-ai/lib/completions/endpoints/base.rb
@@ -59,6 +59,7 @@ module DiscourseAi
DiscourseAi::Completions::Endpoints::OpenAiResponses,
DiscourseAi::Completions::Endpoints::HuggingFace,
DiscourseAi::Completions::Endpoints::Gemini,
+ DiscourseAi::Completions::Endpoints::GoogleVertexAi,
DiscourseAi::Completions::Endpoints::Vllm,
DiscourseAi::Completions::Endpoints::Anthropic,
DiscourseAi::Completions::Endpoints::Cohere,
@@ -80,6 +81,14 @@ module DiscourseAi
raise NotImplementedError
end
+ def supports_environment_credentials?
+ false
+ end
+
+ def requires_configured_url?
+ true
+ end
+
# Register a block that returns a Hash of extra HTTP headers to send
# with each completion request. The block receives a
# RequestHeaderContext and must not raise (errors are swallowed and
diff --git a/plugins/discourse-ai/lib/completions/endpoints/google_vertex_ai.rb b/plugins/discourse-ai/lib/completions/endpoints/google_vertex_ai.rb
new file mode 100644
index 00000000000..8820164eced
--- /dev/null
+++ b/plugins/discourse-ai/lib/completions/endpoints/google_vertex_ai.rb
@@ -0,0 +1,126 @@
+# frozen_string_literal: true
+
+module DiscourseAi
+ module Completions
+ module Endpoints
+ class GoogleVertexAi < Gemini
+ METADATA_TOKEN_URL =
+ "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token"
+ ADC_TOKEN_EXPIRY_BUFFER_SECONDS = 60
+
+ class << self
+ def can_contact?(llm_model)
+ llm_model.provider == "google_vertex_ai"
+ end
+
+ def supports_environment_credentials?
+ true
+ end
+
+ def requires_configured_url?
+ false
+ end
+
+ # Deliberately process-local: this is a machine-identity credential,
+ # so it must not be shared through Redis or across processes that
+ # could run under different service accounts.
+ def adc_token
+ return @adc_token if @adc_token && @adc_token_expires_at.after?(Time.zone.now)
+
+ reset_adc_token_cache!
+
+ payload = fetch_adc_token_payload
+ token = payload&.dig("access_token")
+ expires_in = payload&.dig("expires_in").to_i - ADC_TOKEN_EXPIRY_BUFFER_SECONDS
+
+ if token.present? && expires_in > 0
+ @adc_token = token
+ @adc_token_expires_at = expires_in.seconds.from_now
+ end
+
+ @adc_token
+ end
+
+ def reset_adc_token_cache!
+ @adc_token = nil
+ @adc_token_expires_at = nil
+ end
+
+ private
+
+ def fetch_adc_token_payload
+ uri = URI(METADATA_TOKEN_URL)
+ request = Net::HTTP::Get.new(uri)
+ request["Metadata-Flavor"] = "Google"
+
+ response =
+ Net::HTTP.start(uri.hostname, uri.port, read_timeout: 2, open_timeout: 2) do |http|
+ http.request(request)
+ end
+
+ if response.is_a?(Net::HTTPSuccess)
+ JSON.parse(response.body)
+ else
+ Rails.logger.warn(
+ "DiscourseAi::GoogleVertexAi: ADC token request failed with status #{response.code}",
+ )
+ nil
+ end
+ rescue StandardError => e
+ Rails.logger.warn(
+ "DiscourseAi::GoogleVertexAi: Failed to fetch ADC token: #{e.message}",
+ )
+ nil
+ end
+ end
+
+ def provider_id
+ AiApiAuditLog::Provider::Gemini
+ end
+
+ private
+
+ def model_uri
+ project_id = llm_model.lookup_custom_param("project_id")
+ region = llm_model.lookup_custom_param("region")
+ model_name = vertex_model_name
+
+ base_url =
+ "#{vertex_api_base_url(region)}/v1/projects/#{project_id}/locations/#{region}/publishers/google/models/#{model_name}"
+
+ url =
+ if @streaming_mode
+ "#{base_url}:streamGenerateContent?alt=sse"
+ else
+ "#{base_url}:generateContent"
+ end
+
+ URI(url)
+ end
+
+ def vertex_model_name
+ llm_model.name.to_s.sub(%r{\Agoogle/}, "")
+ end
+
+ def vertex_api_base_url(region)
+ return "https://aiplatform.googleapis.com" if region == "global"
+
+ "https://#{region}-aiplatform.googleapis.com"
+ end
+
+ def prepare_request(payload)
+ headers = {
+ "Content-Type" => "application/json",
+ "Authorization" => "Bearer #{access_token}",
+ }
+
+ Net::HTTP::Post.new(model_uri, headers).tap { |r| r.body = payload }
+ end
+
+ def access_token
+ @access_token ||= llm_model.api_key.presence || self.class.adc_token
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-ai/lib/completions/llm.rb b/plugins/discourse-ai/lib/completions/llm.rb
index f0244d603fd..0ce833d1673 100644
--- a/plugins/discourse-ai/lib/completions/llm.rb
+++ b/plugins/discourse-ai/lib/completions/llm.rb
@@ -32,6 +32,7 @@ module DiscourseAi
cohere
open_ai
google
+ google_vertex_ai
azure
samba_nova
mistral
@@ -50,6 +51,26 @@ module DiscourseAi
DiscourseAi::Tokenizer::BasicTokenizer.available_llm_tokenizers.map(&:name)
end
+ # Endpoint capabilities the admin UI needs to render provider forms.
+ # Endpoints match on provider (and sometimes url), so a lightweight
+ # probe is enough to resolve them.
+ def provider_capabilities
+ probe = Struct.new(:provider, :url)
+
+ provider_names.each_with_object({}) do |provider, capabilities|
+ endpoint =
+ begin
+ DiscourseAi::Completions::Endpoints::Base.endpoint_for(probe.new(provider, ""))
+ rescue UNKNOWN_MODEL
+ nil
+ end
+
+ capabilities[provider] = {
+ requires_configured_url: endpoint ? endpoint.requires_configured_url? : true,
+ }
+ end
+ end
+
def valid_provider_models
return @valid_provider_models if defined?(@valid_provider_models)
diff --git a/plugins/discourse-ai/lib/completions/llm_presets.rb b/plugins/discourse-ai/lib/completions/llm_presets.rb
index a68edd98626..6bef911b567 100644
--- a/plugins/discourse-ai/lib/completions/llm_presets.rb
+++ b/plugins/discourse-ai/lib/completions/llm_presets.rb
@@ -25,7 +25,13 @@ module DiscourseAi
private
def build_presets
- [anthropic_preset, google_preset, open_ai_preset, open_router_preset].freeze
+ [
+ anthropic_preset,
+ google_preset,
+ google_vertex_ai_preset,
+ open_ai_preset,
+ open_router_preset,
+ ].freeze
end
def anthropic_preset
@@ -143,6 +149,29 @@ module DiscourseAi
}
end
+ def google_vertex_ai_preset
+ {
+ id: "google_vertex_ai",
+ models: [
+ model(
+ name: "google/gemini-3-flash",
+ tokens: 1_000_000,
+ display_name: "Gemini 3 Flash (Vertex)",
+ max_output_tokens: 65_000,
+ input_cost: 0.50,
+ cached_input_cost: 0.05,
+ output_cost: 3.0,
+ vision_enabled: true,
+ provider_params: {
+ region: "global",
+ },
+ ),
+ ],
+ tokenizer: DiscourseAi::Tokenizer::GeminiTokenizer,
+ provider: "google_vertex_ai",
+ }
+ end
+
def open_ai_preset
{
id: "open_ai",
diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/google_vertex_ai_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/google_vertex_ai_spec.rb
new file mode 100644
index 00000000000..36f2b879d50
--- /dev/null
+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/google_vertex_ai_spec.rb
@@ -0,0 +1,100 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseAi::Completions::Endpoints::GoogleVertexAi do
+ subject(:endpoint) { described_class.new(model) }
+
+ let(:model) do
+ Fabricate(
+ :llm_model,
+ name: "google/gemini-3.5-flash",
+ provider: "google_vertex_ai",
+ tokenizer: "DiscourseAi::Tokenizer::GeminiTokenizer",
+ url: nil,
+ api_key: nil,
+ provider_params: {
+ project_id: "discourse-project",
+ region: "global",
+ },
+ )
+ end
+
+ before do
+ enable_current_plugin
+ described_class.reset_adc_token_cache!
+ end
+
+ after { described_class.reset_adc_token_cache! }
+
+ def stub_metadata_token(token: "adc-token", expires_in: 3599)
+ stub_request(
+ :get,
+ "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token",
+ ).with(headers: { "Metadata-Flavor" => "Google" }).to_return(
+ status: 200,
+ body: { access_token: token, expires_in: expires_in, token_type: "Bearer" }.to_json,
+ )
+ end
+
+ it "uses the global Vertex AI endpoint and strips the publisher prefix from model names" do
+ expect(endpoint.send(:model_uri).to_s).to eq(
+ "https://aiplatform.googleapis.com/v1/projects/discourse-project/locations/global/publishers/google/models/gemini-3.5-flash:generateContent",
+ )
+ end
+
+ it "uses regional Vertex AI endpoints for regional provider params" do
+ model.provider_params["region"] = "us-central1"
+
+ expect(endpoint.send(:model_uri).to_s).to eq(
+ "https://us-central1-aiplatform.googleapis.com/v1/projects/discourse-project/locations/us-central1/publishers/google/models/gemini-3.5-flash:generateContent",
+ )
+ end
+
+ it "sends a Google Cloud bearer token" do
+ endpoint.stubs(:access_token).returns("vertex-token")
+
+ request = endpoint.send(:prepare_request, "{}")
+
+ expect(request["Authorization"]).to eq("Bearer vertex-token")
+ end
+
+ describe "credential resolution" do
+ it "prefers a configured API key over environment credentials" do
+ model.update!(api_key: "configured-key")
+
+ expect(endpoint.send(:access_token)).to eq("configured-key")
+ end
+
+ it "falls back to the metadata server token when no API key is configured" do
+ stub_metadata_token(token: "adc-token")
+
+ expect(endpoint.send(:access_token)).to eq("adc-token")
+ end
+
+ it "caches the metadata server token across endpoint instances" do
+ metadata_stub = stub_metadata_token(token: "adc-token")
+
+ expect(endpoint.send(:access_token)).to eq("adc-token")
+ expect(described_class.new(model).send(:access_token)).to eq("adc-token")
+
+ expect(metadata_stub).to have_been_requested.once
+ end
+
+ it "does not cache tokens that expire within the safety buffer" do
+ metadata_stub = stub_metadata_token(token: "adc-token", expires_in: 30)
+
+ expect(endpoint.send(:access_token)).to be_nil
+ expect(described_class.new(model).send(:access_token)).to be_nil
+
+ expect(metadata_stub).to have_been_requested.twice
+ end
+
+ it "returns nil when the metadata server is unavailable" do
+ stub_request(
+ :get,
+ "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token",
+ ).to_raise(Errno::ECONNREFUSED)
+
+ expect(endpoint.send(:access_token)).to be_nil
+ end
+ end
+end
diff --git a/plugins/discourse-ai/spec/lib/completions/llm_presets_spec.rb b/plugins/discourse-ai/spec/lib/completions/llm_presets_spec.rb
index 455d73ac71e..08b3b83a53d 100644
--- a/plugins/discourse-ai/spec/lib/completions/llm_presets_spec.rb
+++ b/plugins/discourse-ai/spec/lib/completions/llm_presets_spec.rb
@@ -17,6 +17,19 @@ RSpec.describe DiscourseAi::Completions::LlmPresets do
expect(model).not_to have_key(:provider_params)
end
+ it "includes a Google Vertex AI preset" do
+ preset = described_class.find_provider("google_vertex_ai")
+ model = preset[:models].first
+
+ expect(preset[:provider]).to eq("google_vertex_ai")
+ expect(preset[:tokenizer]).to eq(DiscourseAi::Tokenizer::GeminiTokenizer)
+ expect(model).to include(
+ name: "google/gemini-3-flash",
+ display_name: "Gemini 3 Flash (Vertex)",
+ )
+ expect(model[:provider_params]).to include(region: "global")
+ 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/models/llm_model_spec.rb b/plugins/discourse-ai/spec/models/llm_model_spec.rb
index 20e507a8af4..66986e3fa88 100644
--- a/plugins/discourse-ai/spec/models/llm_model_spec.rb
+++ b/plugins/discourse-ai/spec/models/llm_model_spec.rb
@@ -57,6 +57,54 @@ RSpec.describe LlmModel do
end
end
+ describe "Google Vertex AI provider validation" do
+ def build_vertex_model(provider_params)
+ Fabricate.build(
+ :llm_model,
+ provider: "google_vertex_ai",
+ tokenizer: "DiscourseAi::Tokenizer::GeminiTokenizer",
+ name: "google/gemini-3.5-flash",
+ url: nil,
+ api_key: nil,
+ provider_params: provider_params,
+ )
+ end
+
+ it "does not require a URL or API key" do
+ model = build_vertex_model(project_id: "discourse-project", region: "global")
+
+ expect(model).to be_valid
+ end
+
+ it "requires region and project_id" do
+ model = build_vertex_model({})
+
+ expect(model).not_to be_valid
+ expect(model.errors[:base]).to include(
+ I18n.t("discourse_ai.llm_models.missing_provider_param", param: "region"),
+ I18n.t("discourse_ai.llm_models.missing_provider_param", param: "project_id"),
+ )
+ end
+
+ it "rejects regions that could redirect requests to another host" do
+ model = build_vertex_model(project_id: "discourse-project", region: "evil.example/")
+
+ expect(model).not_to be_valid
+ expect(model.errors[:base]).to include(
+ I18n.t("discourse_ai.llm_models.invalid_provider_param", param: "region"),
+ )
+ end
+
+ it "rejects project ids that don't match the GCP format" do
+ model = build_vertex_model(project_id: "Bad Project!", region: "us-central1")
+
+ expect(model).not_to be_valid
+ expect(model.errors[:base]).to include(
+ I18n.t("discourse_ai.llm_models.invalid_provider_param", param: "project_id"),
+ )
+ end
+ end
+
describe "#estimated_cost_for_tokens" do
it "calculates request, response, cache read, and cache write cost" do
model =
diff --git a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb
index 69cdfb7a020..1f2854ccaf4 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
@@ -48,6 +48,17 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController do
)
end
+ it "includes provider capabilities metadata" do
+ get "/admin/plugins/discourse-ai/ai-llms.json"
+ expect(response).to be_successful
+
+ capabilities = response.parsed_body["meta"]["provider_capabilities"]
+ expect(capabilities.dig("google_vertex_ai", "requires_configured_url")).to eq(false)
+ expect(capabilities.dig("aws_bedrock", "requires_configured_url")).to eq(false)
+ expect(capabilities.dig("aws_bedrock_converse", "requires_configured_url")).to eq(false)
+ expect(capabilities.dig("anthropic", "requires_configured_url")).to eq(true)
+ end
+
it "includes vLLM reasoning controls metadata" do
get "/admin/plugins/discourse-ai/ai-llms.json"
expect(response).to be_successful