From 9818cd5ab916ee47c53f745b913b11a37bfcd7a0 Mon Sep 17 00:00:00 2001 From: "tobias@tobias-weiss.org" Date: Sat, 11 Apr 2026 07:45:55 +0200 Subject: [PATCH] feat(provider): add LiteLLM provider support Add litellm entry to the custom() provider map. Uses the bundled @ai-sdk/openai-compatible SDK with user-configured baseURL. Supports LITELLM_API_KEY env var and apiKey in provider options. Autoloads when baseURL is configured in opencode.json under provider.litellm. --- packages/opencode/src/provider/provider.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index e401a067c716..625cd8ff30d4 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -815,6 +815,27 @@ export namespace Provider { }, }, }), + litellm: Effect.fnUntraced(function* (input: Info) { + const providerConfig = (yield* dep.config()).provider?.["litellm"] + const apiKey = Env.get("LITELLM_API_KEY") + const baseURL = providerConfig?.options?.baseURL ?? providerConfig?.api + + if (!baseURL) { + return { autoload: false } + } + + const options: Record = { baseURL } + if (apiKey) options.apiKey = apiKey + else if (providerConfig?.options?.apiKey) options.apiKey = providerConfig.options.apiKey + + return { + autoload: true, + options, + async getModel(sdk: any, modelID: string) { + return sdk.languageModel(modelID) + }, + } + }), } }