Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

Fix GPT-6 model verification and request parameters (#1012)

Rohith Gandhi G3b509ea17540
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swift
index 8f31b538..39276ad6 100644
--- a/Sources/Fluid/Persistence/SettingsStore.swift
+++ b/Sources/Fluid/Persistence/SettingsStore.swift
@@ -3340,7 +3340,8 @@ final class SettingsStore: ObservableObject {
if let slash = modelLower.firstIndex(of: "/") {
modelLower = String(modelLower[modelLower.index(after: slash)...])
}
- return modelLower.hasPrefix("gpt-5") ||
+ return modelLower.hasPrefix("gpt-6") ||
+ modelLower.hasPrefix("gpt-5") ||
modelLower.contains("gpt-5.") ||
modelLower.hasPrefix("o1") ||
modelLower.hasPrefix("o3") ||
diff --git a/Sources/Fluid/Services/LLMClient.swift b/Sources/Fluid/Services/LLMClient.swift
index d559a36e..d3ed8ee6 100644
--- a/Sources/Fluid/Services/LLMClient.swift
+++ b/Sources/Fluid/Services/LLMClient.swift
@@ -241,7 +241,7 @@ final nonisolated class LLMClient: @unchecked Sendable {
// MARK: - Request Building
- private func buildRequest(_ config: Config) throws -> URLRequest {
+ func buildRequest(_ config: Config) throws -> URLRequest {
// Build endpoint URL
let baseURL = config.baseURL.trimmingCharacters(in: .whitespacesAndNewlines)
guard !baseURL.isEmpty else {
@@ -249,8 +249,8 @@ final nonisolated class LLMClient: @unchecked Sendable {
throw LLMError.invalidURL
}
- let useResponsesAPI = self.shouldUseResponsesAPI(for: config, baseURL: baseURL)
- let endpoint = self.endpoint(for: baseURL, useResponsesAPI: useResponsesAPI)
+ let useResponsesAPI = Self.shouldUseResponsesAPI(baseURL: baseURL, model: config.model)
+ let endpoint = Self.endpoint(for: baseURL, useResponsesAPI: useResponsesAPI)
guard let url = URL(string: endpoint) else {
throw LLMError.invalidURL
@@ -284,11 +284,11 @@ final nonisolated class LLMClient: @unchecked Sendable {
return request
}
- private func appendingPath(_ path: String, to baseURL: String) -> String {
+ private static func appendingPath(_ path: String, to baseURL: String) -> String {
baseURL.hasSuffix("/") ? "\(baseURL)\(path)" : "\(baseURL)/\(path)"
}
- private func endpoint(for baseURL: String, useResponsesAPI: Bool) -> String {
+ static func endpoint(for baseURL: String, useResponsesAPI: Bool) -> String {
if useResponsesAPI {
if baseURL.contains("/responses") {
return baseURL
@@ -296,7 +296,7 @@ final nonisolated class LLMClient: @unchecked Sendable {
if baseURL.contains("/chat/completions") {
return baseURL.replacingOccurrences(of: "/chat/completions", with: "/responses")
}
- return self.appendingPath("responses", to: baseURL)
+ return Self.appendingPath("responses", to: baseURL)
}
if baseURL.contains("/chat/completions") ||
@@ -305,10 +305,10 @@ final nonisolated class LLMClient: @unchecked Sendable {
{
return baseURL
}
- return self.appendingPath("chat/completions", to: baseURL)
+ return Self.appendingPath("chat/completions", to: baseURL)
}
- private func shouldUseResponsesAPI(for config: Config, baseURL: String) -> Bool {
+ static func shouldUseResponsesAPI(baseURL: String, model: String) -> Bool {
if baseURL.contains("/responses") {
return true
}
@@ -317,8 +317,9 @@ final nonisolated class LLMClient: @unchecked Sendable {
url.host?.lowercased() == "api.openai.com"
else { return false }
- let modelLower = config.model.lowercased()
- return modelLower.hasPrefix("gpt-5") ||
+ let modelLower = model.lowercased()
+ return modelLower.hasPrefix("gpt-6") ||
+ modelLower.hasPrefix("gpt-5") ||
modelLower.hasPrefix("o1") ||
modelLower.hasPrefix("o3") ||
modelLower.hasPrefix("o4")
@@ -376,7 +377,8 @@ final nonisolated class LLMClient: @unchecked Sendable {
if let slash = modelLower.firstIndex(of: "/") {
modelLower = String(modelLower[modelLower.index(after: slash)...])
}
- return modelLower.hasPrefix("gpt-5") ||
+ return modelLower.hasPrefix("gpt-6") ||
+ modelLower.hasPrefix("gpt-5") ||
modelLower.contains("gpt-5.") ||
modelLower.hasPrefix("o1") ||
modelLower.hasPrefix("o3") ||
diff --git a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift
index a204066b..bd0d28d2 100644
--- a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift
+++ b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift
@@ -839,7 +839,10 @@ final class AIEnhancementSettingsViewModel: ObservableObject {
}
return
}
- let usesResponsesAPI = self.shouldVerifyWithResponsesAPI(baseURL: baseURL, model: trimmedModel)
+ let usesResponsesAPI = LLMClient.shouldUseResponsesAPI(
+ baseURL: baseURL.trimmingCharacters(in: .whitespacesAndNewlines),
+ model: trimmedModel
+ )
let verificationIdentity = ProviderModelVerificationStore.identity(
providerID: providerID, baseURL: baseURL, apiKey: apiKey, model: trimmedModel
@@ -853,25 +856,15 @@ final class AIEnhancementSettingsViewModel: ObservableObject {
let endpoint = baseURL.trimmingCharacters(in: .whitespacesAndNewlines)
let fullURL: String
- if usesResponsesAPI {
- if endpoint.contains("/responses") {
- fullURL = endpoint
- } else if endpoint.contains("/chat/completions") {
- fullURL = endpoint.replacingOccurrences(of: "/chat/completions", with: "/responses")
- } else {
- fullURL = endpoint + "/responses"
- }
- } else if isAnthropic {
+ if isAnthropic && !usesResponsesAPI {
// Anthropic uses /messages endpoint, not /chat/completions
if endpoint.contains("/messages") {
fullURL = endpoint
} else {
fullURL = endpoint + "/messages"
}
- } else if endpoint.contains("/chat/completions") || endpoint.contains("/api/chat") || endpoint.contains("/api/generate") {
- fullURL = endpoint
} else {
- fullURL = endpoint + "/chat/completions"
+ fullURL = LLMClient.endpoint(for: endpoint, useResponsesAPI: usesResponsesAPI)
}
// Debug logging
@@ -1058,22 +1051,6 @@ final class AIEnhancementSettingsViewModel: ObservableObject {
return "HTTP \(statusCode)"
}
- private func shouldVerifyWithResponsesAPI(baseURL: String, model: String) -> Bool {
- if baseURL.contains("/responses") {
- return true
- }
-
- guard let url = URL(string: baseURL),
- url.host?.lowercased() == "api.openai.com"
- else { return false }
-
- let modelLower = model.lowercased()
- return modelLower.hasPrefix("gpt-5") ||
- modelLower.hasPrefix("o1") ||
- modelLower.hasPrefix("o3") ||
- modelLower.hasPrefix("o4")
- }
-
/// Interprets network errors with actionable guidance
private func interpretNetworkError(_ error: Error, providerID: String) -> String {
let providerName = ModelRepository.shared.displayName(for: providerID)
diff --git a/Tests/FluidDictationIntegrationTests/LLMClientRequestBodyTests.swift b/Tests/FluidDictationIntegrationTests/LLMClientRequestBodyTests.swift
index e4fa07b4..e668313d 100644
--- a/Tests/FluidDictationIntegrationTests/LLMClientRequestBodyTests.swift
+++ b/Tests/FluidDictationIntegrationTests/LLMClientRequestBodyTests.swift
@@ -109,6 +109,80 @@ final class LLMClientRequestBodyTests: XCTestCase {
XCTAssertEqual(messages[0]["content"] as? String, "Clean <text>hello</text>")
}
+ // Regression: GPT-6 fell through to Chat Completions with legacy max_tokens (#1010).
+ func testGPT6RequestsUseResponsesAndOutputTokenLimit() throws {
+ for model in ["gpt-6-luna", "gpt-6-sol", "gpt-6-astra", "gpt-6-luna-2026-09-22"] {
+ for baseURL in ["https://api.openai.com/v1", "https://api.openai.com/v1/", "https://api.openai.com/v1/chat/completions"] {
+ let config = LLMClient.Config(
+ messages: [["role": "user", "content": "test"]],
+ model: model,
+ baseURL: baseURL,
+ apiKey: "",
+ streaming: false,
+ maxTokens: 50
+ )
+ let request = try LLMClient.shared.buildRequest(config)
+ XCTAssertEqual(request.url?.path, "/v1/responses", model)
+ let data = try XCTUnwrap(request.httpBody)
+ let body = try XCTUnwrap(JSONSerialization.jsonObject(with: data) as? [String: Any])
+ XCTAssertEqual(body["max_output_tokens"] as? Int, 50, model)
+ XCTAssertNil(body["max_tokens"], model)
+ XCTAssertNil(body["max_completion_tokens"], model)
+ XCTAssertNotNil(body["input"], model)
+ XCTAssertNil(body["temperature"], model)
+ }
+ }
+ }
+
+ func testGPT6CompatibleProvidersKeepChatCompletionsWithModernTokenLimit() throws {
+ for model in ["gpt-6-luna", "openai/gpt-6-luna", "OPENAI/GPT-6-SOL"] {
+ let config = LLMClient.Config(
+ messages: [["role": "user", "content": "test"]],
+ model: model,
+ baseURL: "https://openrouter.ai/api/v1",
+ apiKey: "",
+ streaming: false,
+ maxTokens: 50
+ )
+ let request = try LLMClient.shared.buildRequest(config)
+ XCTAssertEqual(request.url?.path, "/api/v1/chat/completions", model)
+ let data = try XCTUnwrap(request.httpBody)
+ let body = try XCTUnwrap(JSONSerialization.jsonObject(with: data) as? [String: Any])
+ XCTAssertEqual(body["max_completion_tokens"] as? Int, 50, model)
+ XCTAssertNil(body["max_tokens"], model)
+ XCTAssertNil(body["max_output_tokens"], model)
+ }
+ }
+
+ func testSharedEndpointBuilderHandlesTrailingSlashesAndExplicitEndpoints() {
+ let cases: [(baseURL: String, responses: Bool, expected: String)] = [
+ ("https://api.openai.com/v1/", true, "https://api.openai.com/v1/responses"),
+ ("https://example.com/v1/", false, "https://example.com/v1/chat/completions"),
+ ("https://api.openai.com/v1/chat/completions", true, "https://api.openai.com/v1/responses"),
+ ("https://example.com/v1/responses", true, "https://example.com/v1/responses"),
+ ("https://example.com/v1/chat/completions", false, "https://example.com/v1/chat/completions"),
+ ("http://localhost:11434/api/chat", false, "http://localhost:11434/api/chat"),
+ ("http://localhost:11434/api/generate", false, "http://localhost:11434/api/generate"),
+ ]
+ for testCase in cases {
+ XCTAssertEqual(
+ LLMClient.endpoint(for: testCase.baseURL, useResponsesAPI: testCase.responses),
+ testCase.expected
+ )
+ }
+ }
+
+ func testResponsesRoutingPreservesExistingModelsAndExplicitEndpoints() {
+ for model in ["gpt-5", "o1", "o3-mini", "o4-mini"] {
+ XCTAssertTrue(LLMClient.shouldUseResponsesAPI(baseURL: "https://api.openai.com/v1", model: model))
+ }
+ for model in ["gpt-4o", "gpt-4.1", "llama3"] {
+ XCTAssertFalse(LLMClient.shouldUseResponsesAPI(baseURL: "https://api.openai.com/v1", model: model))
+ }
+ XCTAssertTrue(LLMClient.shouldUseResponsesAPI(baseURL: "https://example.com/v1/responses", model: "custom"))
+ XCTAssertFalse(LLMClient.shouldUseResponsesAPI(baseURL: "https://api.openai.com.example.com/v1", model: "gpt-6-luna"))
+ }
+
// MARK: - Dictation custom prompt resolution
func testCustomPromptOnly_omitsBasePromptFromEffectivePromptAndRequestBody() {
diff --git a/Tests/FluidDictationIntegrationTests/TemperatureSupportTests.swift b/Tests/FluidDictationIntegrationTests/TemperatureSupportTests.swift
index 75a91cc8..1c319a9b 100644
--- a/Tests/FluidDictationIntegrationTests/TemperatureSupportTests.swift
+++ b/Tests/FluidDictationIntegrationTests/TemperatureSupportTests.swift
@@ -33,7 +33,7 @@ final class TemperatureSupportTests: XCTestCase {
}
func testTemperatureUnsupported_openAIReasoningModels() {
- for model in ["o1", "o3-mini", "gpt-5", "openai/gpt-oss-120b"] {
+ for model in ["o1", "o3-mini", "gpt-5", "gpt-6-luna", "gpt-6-sol", "gpt-6-astra", "openai/gpt-6-luna", "openai/gpt-oss-120b"] {
XCTAssertTrue(
SettingsStore.shared.isTemperatureUnsupported(model),
"\(model) is a reasoning model and must not receive `temperature`"