Skip to content

Commit 2986362

Browse files
waleedlatif1TheodoreSpeaksSg312icecrasher321
authored
feat(providers): add NVIDIA NIM and Z.ai providers (#5560)
* v0.6.29: login improvements, posthog telemetry (#4026) * feat(posthog): Add tracking on mothership abort (#4023) Co-authored-by: Theodore Li <theo@sim.ai> * fix(login): fix captcha headers for manual login (#4025) * fix(signup): fix turnstile key loading * fix(login): fix captcha header passing * Catch user already exists, remove login form captcha * feat(providers): add NVIDIA NIM and Z.ai providers - NVIDIA NIM (BYOK): Nemotron model family (70B/Ultra-253B/Super-49B v1.5, Nemotron-3 Nano/Super/Ultra) via integrate.api.nvidia.com's OpenAI-compatible API - Z.ai (hosted): GLM model family (5.2 down to 4-32B) via api.z.ai's OpenAI-compatible API, bare glm-* model ids with no provider prefix, Sim-provided key rotation (ZAI_API_KEY_1/2/3) matching openai/anthropic/google - Z.ai tool_choice is forced to 'auto' since the API only documents auto support; forced/none tool_choice from prepareToolsWithUsageControl is ignored with a warning log instead of being sent to the API * fix(providers): scope zai model routing to the exact catalog Drop the /^glm/ fallback pattern - it would overmatch any unrelated self-hosted "glm-*" model (e.g. a custom vLLM/LiteLLM deployment) and misroute it to Z.ai's hosted, Sim-billed key. Routing now relies solely on the exact model-id match against zai's static catalog. * fix(providers): wire thinking/reasoning_effort into Z.ai requests request.thinkingLevel and request.reasoningEffort were computed but never mapped onto the Z.ai payload, so the thinking toggle and GLM-5.2's reasoning_effort control silently no-op'd and always ran on Z.ai's server-side default instead of the user's selection. * fix(providers): route Z.ai through the workspace BYOK resolver too getApiKeyWithBYOK (the resolver actually used by workspace provider runs, per providers/index.ts) only rotated server keys for openai/anthropic/google/mistral, so GLM calls without a user apiKey failed even with ZAI_API_KEY_1/2/3 configured — getApiKey in providers/utils.ts had zai wired but that's not the codepath workspace runs go through. Add zai to the hosted-check condition, and register it as a BYOKProviderId so a workspace can also bring its own Z.ai key. --------- Co-authored-by: Theodore Li <theodoreqili@gmail.com> Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com> Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com> Co-authored-by: Theodore Li <theo@sim.ai>
1 parent 7d1c927 commit 2986362

17 files changed

Lines changed: 1811 additions & 3 deletions

File tree

apps/sim/components/icons.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,6 +3687,38 @@ export const SakanaIcon = (props: SVGProps<SVGSVGElement>) => (
36873687
</svg>
36883688
)
36893689

3690+
export const NvidiaIcon = (props: SVGProps<SVGSVGElement>) => (
3691+
<svg
3692+
{...props}
3693+
height='1em'
3694+
viewBox='30 28 280 172'
3695+
width='1em'
3696+
xmlns='http://www.w3.org/2000/svg'
3697+
>
3698+
<title>NVIDIA</title>
3699+
<path
3700+
d='M82.211,102.414c0,0,22.504-33.203,67.437-36.638V53.73c-49.769,3.997-92.867,46.149-92.867,46.149s24.41,70.565,92.867,77.026v-12.804C99.411,157.781,82.211,102.414,82.211,102.414z M149.648,138.637v11.726c-37.968-6.769-48.507-46.237-48.507-46.237s18.23-20.195,48.507-23.47v12.867c-0.023,0-0.039-0.007-0.058-0.007c-15.891-1.907-28.305,12.938-28.305,12.938S128.243,131.445,149.648,138.637 M149.648,31.512V53.73c1.461-0.112,2.922-0.207,4.391-0.257c56.582-1.907,93.449,46.406,93.449,46.406s-42.343,51.488-86.457,51.488c-4.043,0-7.828-0.375-11.383-1.005v13.739c3.04,0.386,6.192,0.613,9.481,0.613c41.051,0,70.738-20.965,99.484-45.778c4.766,3.817,24.278,13.103,28.289,17.168c-27.332,22.883-91.031,41.329-127.144,41.329c-3.481,0-6.824-0.211-10.11-0.528v19.306h156.032V31.512H149.648z M149.648,80.656V65.777c1.446-0.101,2.903-0.179,4.391-0.226c40.688-1.278,67.382,34.965,67.382,34.965s-28.832,40.043-59.746,40.043c-4.449,0-8.438-0.715-12.028-1.922V93.523c15.84,1.914,19.028,8.911,28.551,24.786l21.18-17.859c0,0-15.461-20.277-41.524-20.277C155.021,80.172,152.31,80.371,149.648,80.656'
3701+
fill='#77B900'
3702+
/>
3703+
</svg>
3704+
)
3705+
3706+
export const ZaiIcon = (props: SVGProps<SVGSVGElement>) => (
3707+
<svg {...props} height='1em' viewBox='0 0 30 30' width='1em' xmlns='http://www.w3.org/2000/svg'>
3708+
<title>Z.ai</title>
3709+
<path
3710+
d='M24.51,28.51H5.49c-2.21,0-4-1.79-4-4V5.49c0-2.21,1.79-4,4-4h19.03c2.21,0,4,1.79,4,4v19.03C28.51,26.72,26.72,28.51,24.51,28.51z'
3711+
fill='#2D2D2D'
3712+
/>
3713+
<path
3714+
d='M15.47,7.1l-1.3,1.85c-0.2,0.29-0.54,0.47-0.9,0.47h-7.1V7.09C6.16,7.1,15.47,7.1,15.47,7.1z'
3715+
fill='#FFFFFF'
3716+
/>
3717+
<polygon fill='#FFFFFF' points='24.3,7.1 13.14,22.91 5.7,22.91 16.86,7.1' />
3718+
<path d='M14.53,22.91l1.31-1.86c0.2-0.29,0.54-0.47,0.9-0.47h7.09v2.33H14.53z' fill='#FFFFFF' />
3719+
</svg>
3720+
)
3721+
36903722
export function MetaIcon(props: SVGProps<SVGSVGElement>) {
36913723
const id = useId()
36923724
const gradient1Id = `meta_gradient_1_${id}`

apps/sim/lib/api-key/byok.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ export async function getApiKeyWithBYOK(
204204
const isClaudeModel = provider === 'anthropic'
205205
const isGeminiModel = provider === 'google'
206206
const isMistralModel = provider === 'mistral'
207+
const isZaiModel = provider === 'zai'
207208

208209
const byokProviderId = isGeminiModel ? 'google' : (provider as BYOKProviderId)
209210

210211
if (
211212
isHosted &&
212213
workspaceId &&
213-
(isOpenAIModel || isClaudeModel || isGeminiModel || isMistralModel)
214+
(isOpenAIModel || isClaudeModel || isGeminiModel || isMistralModel || isZaiModel)
214215
) {
215216
const hostedModels = getHostedModels()
216217
const isModelHosted = hostedModels.some((m) => m.toLowerCase() === model.toLowerCase())

apps/sim/lib/api/contracts/byok-keys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const byokProviderIdSchema = z.enum([
66
'anthropic',
77
'google',
88
'mistral',
9+
'zai',
910
'fireworks',
1011
'together',
1112
'baseten',

apps/sim/lib/core/config/api-keys.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export function getRotatingApiKey(provider: string): string {
1111
provider !== 'openai' &&
1212
provider !== 'anthropic' &&
1313
provider !== 'gemini' &&
14-
provider !== 'cohere'
14+
provider !== 'cohere' &&
15+
provider !== 'zai'
1516
) {
1617
throw new Error(`No rotation implemented for provider: ${provider}`)
1718
}
@@ -34,6 +35,10 @@ export function getRotatingApiKey(provider: string): string {
3435
if (env.COHERE_API_KEY_1) keys.push(env.COHERE_API_KEY_1)
3536
if (env.COHERE_API_KEY_2) keys.push(env.COHERE_API_KEY_2)
3637
if (env.COHERE_API_KEY_3) keys.push(env.COHERE_API_KEY_3)
38+
} else if (provider === 'zai') {
39+
if (env.ZAI_API_KEY_1) keys.push(env.ZAI_API_KEY_1)
40+
if (env.ZAI_API_KEY_2) keys.push(env.ZAI_API_KEY_2)
41+
if (env.ZAI_API_KEY_3) keys.push(env.ZAI_API_KEY_3)
3742
}
3843

3944
if (keys.length === 0) {

apps/sim/lib/core/config/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export const env = createEnv({
144144
GEMINI_API_KEY_1: z.string().min(1).optional(), // Primary Gemini API key
145145
GEMINI_API_KEY_2: z.string().min(1).optional(), // Additional Gemini API key for load balancing
146146
GEMINI_API_KEY_3: z.string().min(1).optional(), // Additional Gemini API key for load balancing
147+
ZAI_API_KEY_1: z.string().min(1).optional(), // Primary Z.ai API key for load balancing
148+
ZAI_API_KEY_2: z.string().min(1).optional(), // Additional Z.ai API key for load balancing
149+
ZAI_API_KEY_3: z.string().min(1).optional(), // Additional Z.ai API key for load balancing
147150
OLLAMA_URL: z.string().url().optional(), // Ollama local LLM server URL
148151
VLLM_BASE_URL: z.string().url().optional(), // vLLM self-hosted base URL (OpenAI-compatible)
149152
VLLM_API_KEY: z.string().optional(), // Optional bearer token for vLLM

apps/sim/lib/tokenization/constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,21 @@ export const TOKENIZATION_CONFIG = {
6161
confidence: 'medium',
6262
supportedMethods: ['heuristic', 'fallback'],
6363
},
64+
nvidia: {
65+
avgCharsPerToken: 4,
66+
confidence: 'medium',
67+
supportedMethods: ['heuristic', 'fallback'],
68+
},
6469
meta: {
6570
avgCharsPerToken: 4,
6671
confidence: 'medium',
6772
supportedMethods: ['heuristic', 'fallback'],
6873
},
74+
zai: {
75+
avgCharsPerToken: 4,
76+
confidence: 'medium',
77+
supportedMethods: ['heuristic', 'fallback'],
78+
},
6979
ollama: {
7080
avgCharsPerToken: 4,
7181
confidence: 'low',

apps/sim/providers/attachments.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export type AttachmentProvider =
3636
| 'deepseek'
3737
| 'cerebras'
3838
| 'sakana'
39+
| 'nvidia'
3940
| 'meta'
41+
| 'zai'
4042

4143
export interface PreparedProviderAttachment {
4244
file: UserFile
@@ -124,7 +126,9 @@ const UNSUPPORTED_FILE_PROVIDERS = new Set<AttachmentProvider>([
124126
'deepseek',
125127
'cerebras',
126128
'sakana',
129+
'nvidia',
127130
'meta',
131+
'zai',
128132
])
129133

130134
const PROVIDER_SUPPORTED_LABELS: Record<AttachmentProvider, string> = {
@@ -145,7 +149,9 @@ const PROVIDER_SUPPORTED_LABELS: Record<AttachmentProvider, string> = {
145149
deepseek: 'no file attachments in the current API adapter',
146150
cerebras: 'no file attachments in the current API adapter',
147151
sakana: 'no file attachments in the current API adapter',
152+
nvidia: 'no file attachments in the current API adapter',
148153
meta: 'no file attachments in the current API adapter',
154+
zai: 'no file attachments in the current API adapter',
149155
}
150156

151157
export function getAttachmentProvider(providerId: ProviderId | string): AttachmentProvider | null {
@@ -166,7 +172,9 @@ export function getAttachmentProvider(providerId: ProviderId | string): Attachme
166172
if (providerId === 'deepseek') return 'deepseek'
167173
if (providerId === 'cerebras') return 'cerebras'
168174
if (providerId === 'sakana') return 'sakana'
175+
if (providerId === 'nvidia') return 'nvidia'
169176
if (providerId === 'meta') return 'meta'
177+
if (providerId === 'zai') return 'zai'
170178
return null
171179
}
172180

@@ -315,7 +323,9 @@ function isMimeTypeSupportedByProvider(
315323
case 'deepseek':
316324
case 'cerebras':
317325
case 'sakana':
326+
case 'nvidia':
318327
case 'meta':
328+
case 'zai':
319329
return false
320330
default: {
321331
const _exhaustive: never = provider

apps/sim/providers/models.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { describe, expect, it } from 'vitest'
55
import {
66
getBaseModelProviders,
7+
getHostedModels,
78
orderModelIdsByReleaseDate,
89
PROVIDER_DEFINITIONS,
910
} from '@/providers/models'
@@ -134,3 +135,86 @@ describe('sakana provider definition', () => {
134135
expect(baseModels['fugu-ultra']).toBe('sakana')
135136
})
136137
})
138+
139+
describe('nvidia provider definition', () => {
140+
const nvidia = PROVIDER_DEFINITIONS.nvidia
141+
142+
const expectedModels = [
143+
{ id: 'nvidia/llama-3.1-nemotron-70b-instruct', contextWindow: 128000 },
144+
{ id: 'nvidia/llama-3.1-nemotron-ultra-253b-v1', contextWindow: 131072 },
145+
{ id: 'nvidia/llama-3.3-nemotron-super-49b-v1.5', contextWindow: 131072 },
146+
{ id: 'nvidia/nemotron-3-nano-30b-a3b', contextWindow: 262144 },
147+
{ id: 'nvidia/nemotron-3-super-120b-a12b', contextWindow: 1048576 },
148+
{ id: 'nvidia/nemotron-3-ultra-550b-a55b', contextWindow: 1048576 },
149+
]
150+
151+
it('is registered with the current-gen Super model as the default', () => {
152+
expect(nvidia).toBeDefined()
153+
expect(nvidia.id).toBe('nvidia')
154+
expect(nvidia.defaultModel).toBe('nvidia/nemotron-3-super-120b-a12b')
155+
expect(nvidia.modelPatterns).toEqual([/^nvidia\//])
156+
})
157+
158+
it('exposes all six Nemotron models with the documented context windows', () => {
159+
expect(nvidia.models.map((m) => m.id)).toEqual(expectedModels.map((m) => m.id))
160+
for (const expected of expectedModels) {
161+
const model = nvidia.models.find((m) => m.id === expected.id)
162+
expect(model?.contextWindow).toBe(expected.contextWindow)
163+
}
164+
})
165+
166+
it('routes every nvidia model ID to the nvidia provider', () => {
167+
const baseModels = getBaseModelProviders()
168+
for (const expected of expectedModels) {
169+
expect(baseModels[expected.id]).toBe('nvidia')
170+
}
171+
})
172+
})
173+
174+
describe('zai provider definition', () => {
175+
const zai = PROVIDER_DEFINITIONS.zai
176+
177+
const expectedModels = [
178+
{ id: 'glm-5.2', contextWindow: 1000000 },
179+
{ id: 'glm-5.1', contextWindow: 200000 },
180+
{ id: 'glm-5', contextWindow: 200000 },
181+
{ id: 'glm-5-turbo', contextWindow: 200000 },
182+
{ id: 'glm-4.7', contextWindow: 200000 },
183+
{ id: 'glm-4.7-flashx', contextWindow: 200000 },
184+
{ id: 'glm-4.6', contextWindow: 200000 },
185+
{ id: 'glm-4.5', contextWindow: 128000 },
186+
{ id: 'glm-4.5-air', contextWindow: 128000 },
187+
{ id: 'glm-4.5-x', contextWindow: 128000 },
188+
{ id: 'glm-4.5-airx', contextWindow: 128000 },
189+
{ id: 'glm-4-32b-0414-128k', contextWindow: 128000 },
190+
]
191+
192+
it('is registered with a bare glm-4.6 as the default model', () => {
193+
expect(zai).toBeDefined()
194+
expect(zai.id).toBe('zai')
195+
expect(zai.defaultModel).toBe('glm-4.6')
196+
expect(zai.defaultModel.startsWith('zai/')).toBe(false)
197+
// No fallback pattern — an unscoped `/^glm/` would overmatch unrelated self-hosted
198+
// "glm-*" models and misroute them to Z.ai's hosted billing.
199+
expect(zai.modelPatterns).toEqual([])
200+
})
201+
202+
it('exposes every GLM model with the documented context window', () => {
203+
expect(zai.models.map((m) => m.id)).toEqual(expectedModels.map((m) => m.id))
204+
for (const expected of expectedModels) {
205+
const model = zai.models.find((m) => m.id === expected.id)
206+
expect(model?.contextWindow).toBe(expected.contextWindow)
207+
}
208+
})
209+
210+
it('routes every bare glm-* model ID to the zai provider', () => {
211+
const baseModels = getBaseModelProviders()
212+
for (const expected of expectedModels) {
213+
expect(baseModels[expected.id]).toBe('zai')
214+
}
215+
})
216+
217+
it('is included in getHostedModels since Sim provides the Z.ai key server-side', () => {
218+
expect(getHostedModels()).toContain('glm-4.6')
219+
})
220+
})

0 commit comments

Comments
 (0)