Skip to content

Commit 1620bb6

Browse files
author
brettheap
committed
fix(provider): validate baseURL format before passing to SDK
Prevents ERR_INVALID_URL by validating baseURL values before passing to AI SDK. The SDK's nullish coalescing (??) only catches null/undefined, not empty strings or invalid values like 'anthropic'. When an invalid baseURL is provided, it's filtered out and the SDK uses its default endpoint instead.
1 parent 41f9a58 commit 1620bb6

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

packages/opencode/src/provider/provider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,15 @@ export namespace Provider {
869869
options["includeUsage"] = true
870870
}
871871

872-
if (!options["baseURL"]) options["baseURL"] = model.api.url
872+
// Clean up invalid baseURL to let SDK use its default
873+
// baseURL must be a valid URL (starts with http:// or https://)
874+
const isValidUrl = (url: string | undefined | null): url is string => {
875+
return typeof url === "string" && (url.startsWith("http://") || url.startsWith("https://"))
876+
}
877+
if (!isValidUrl(options["baseURL"])) {
878+
delete options["baseURL"]
879+
if (isValidUrl(model.api.url)) options["baseURL"] = model.api.url
880+
}
873881
if (options["apiKey"] === undefined && provider.key) options["apiKey"] = provider.key
874882
if (model.headers)
875883
options["headers"] = {

0 commit comments

Comments
 (0)