AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(ai-providers): add meta and nvidia as ai providers (#17037)
Louai Boumedienee6e2abb6b0c7
diff --git a/brain/knowledge/ai-intelligence/ai-providers.md b/brain/knowledge/ai-intelligence/ai-providers.mdindex 13218449c5d..7b26e1b91ed 100644--- a/brain/knowledge/ai-intelligence/ai-providers.md+++ b/brain/knowledge/ai-intelligence/ai-providers.md@@ -9,7 +9,7 @@ Lets platform admins configure one or more LLM backends for AI pieces in flows.### Entities & services- **AIProvider** — platform-scoped: `displayName`, `platformId` (indexed with `provider`, NOT unique — a platform can hold multiple keys per provider since the 2026-08 providers redesign), `provider` (AIProviderName enum), `auth` (EncryptedObject, AES-256 at rest), `config` (JSON), `enabledForChat`, plus per-key scoping: `modelScope` (`all|selected`) + `modelIds[]`, and `projectScope` (`all|selected|except`) + `projectIds[]` (GIN-indexed).- Backend under `packages/server/api/src/app/ai/`; shared schemas in `core/shared/.../ai-providers/`.-- Supported providers (10): `openai`, `anthropic`, `google`, `azure`, `openrouter`, `bedrock`, `mistral`, `cloudflare-gateway`, `custom` (OpenAI-compatible, e.g. Ollama/LM Studio), `activepieces` (auto-provisioned via OpenRouter).+- Supported providers (19): `openai`, `anthropic`, `google`, `azure`, `openrouter`, `bedrock`, `vertex`, `mistral`, `cloudflare-gateway`, the OpenAI-compatible vendors `xai`, `deepseek`, `zai`, `qwen`, `minimax`, `moonshot`, `meta`, `nvidia`, `custom` (OpenAI-compatible, e.g. Ollama/LM Studio), and `activepieces` (auto-provisioned via OpenRouter).### How it works- `GET /` list (auto-creates ACTIVEPIECES when `aiCreditsEnabled`); `GET /:provider/models` (cached); `POST /` create (validates creds first); `POST /:id` update; `DELETE /:id`.@@ -163,7 +163,7 @@ after a file without chat keys it seeds the chat list from the live flow list.- **`secret: true` on a credential field is not about masking, it is what stops a stored credential being prefilled back into the form.** In `PROVIDER_CREDENTIAL_FIELDS` the flag feeds `secretKeysOf`, and the dialog's default-values builder blanks exactly those keys when reopening an existing key; the password-style `Input` is a side effect of the same flag, not its purpose. So dropping it to change how a field *renders* silently turns a stored secret into a prefilled value. Render differently instead: `type` (`dictionary`, `textarea`) is checked ahead of `secret` in `CredentialFieldInput`, so a field can keep the flag and still draw as something other than a masked input — that is how the Vertex service-account JSON gets a monospace textarea while staying blanked on edit. Both the initialiser and the required-field check filter only `dictionary`, so any other `type` is initialised and validated like a normal credential.- **Adding a provider is a leaf change, and the credential fields are the only part that is not.** A new vendor touches six places: the `AIProviderName` enum (`packages/core/utils/.../permission.ts`), its auth/config schemas plus the two unions and `ProviderConfigUnion` in `packages/core/shared/.../management/ai-providers/index.ts` (all in the per-provider region, well above the generic request/response schemas at the bottom), a strategy file registered in `ai/providers/index.ts`, the model factory switch, name/logo/markdown in `packages/web/src/features/agents/ai-providers.ts`, and translation keys. None of that is the credential form: extra fields beyond `apiKey` (Azure's `resourceName`, Bedrock's region) are declared in **one** file — `PROVIDER_CREDENTIAL_FIELDS` in `.../setup/ai/providers-tab/provider-credentials.ts`, which falls back to `DEFAULT_CREDENTIAL_FIELDS` (a single `apiKey`) for any provider with no entry, so a plain API-key vendor needs no UI work at all. That file replaced the deleted `universal-pieces/upsert-provider-config-form.tsx` in the multi-key redesign, so a provider authored against an older branch loses its custom fields on merge **silently** — git resolves delete-vs-modify by taking the deletion, no conflict marker, and the provider just becomes unconfigurable in the admin UI. A vendor with no `/models` endpoint also belongs in `MANUAL_MODEL_PROVIDERS` in that same file (`CUSTOM`, `CLOUDFLARE_GATEWAY`) so the admin enters model ids by hand. Everything else about a provider is orthogonal to multi-key: that is a table-level change (drop `UNIQUE (platformId, provider)`, add the four scope columns, keep a unique partial index for `activepieces` only), so a provider inherits multi-key with no provider-side code, and the admin providers-tab enumerates `SUPPORTED_AI_PROVIDERS` from `packages/web/src/features/agents/ai-providers.ts` rather than a catalog of its own, so a new vendor appears there on its own. When basing provider work off a branch that predates the redesign, re-check `provider-credentials.ts` after the merge.- **The OpenAI-compatible vendors (xAI, DeepSeek, Z.ai, Qwen, MiniMax, Moonshot) share one strategy rather than a file each**, via `openAiCompatibleVendor({ name, provider })` in `ai/providers/`, with defaults in `OPENAI_COMPATIBLE_VENDOR_BASE_URLS` and an optional per-key `baseUrl` override because four of them run separate China and international endpoints. Their `listModels` GETs `{baseUrl}/models`, which the vendor docs mostly do not document — **confirmed working against live keys for DeepSeek, Z.ai, MiniMax and Moonshot** (Qwen still unverified), so don't redo that research. If a future vendor turns out to lack `/models`, the fallback is the manual-models path rather than a bespoke strategy. Unlike its siblings this factory uses `safeHttp.axios`, not `httpClient` from `pieces-common`: the base URL is admin-supplied, so it must go through the SSRF filter.-- **Adding a provider compiles fine and still breaks flows, because the two model factories fail differently.** `createLanguageModel` in `@activepieces/ai-providers` ends its switch with `const exhaustiveCheck: never = provider`, so a missing provider is a *compile* error. The deliberately duplicated `buildLanguageModel` inside the AI piece (`pieces/community/ai/.../common/ai-sdk.ts`, kept on ai@6 because a v4 model cannot cross into the engine) ends with `default: throw new Error(...)` — so a provider wired only into the first one type-checks, ships, connects happily in the admin UI, and then throws `Provider <name> is not supported` the moment someone uses it in a flow step. That is the `.claude/rules/self-hosting.md` antipattern exactly. Wire **both** factories, and note `buildNativeImageModel` in that same file is a third switch, and its miss is worse than a throw: `createAIModel` does `if (imageModel) return imageModel` and otherwise **falls through to `buildLanguageModel`**, so a provider absent from that switch answers an image request with a *language* model rather than erroring. `NO_IMAGE_GENERATION_PROVIDERS` is what turns that into the clear `does not support image models` message, so a provider belongs there until images are actually wired — the entry is load bearing, not cosmetic.+- **Adding an API-key vendor touches these files, and two misses only fail at runtime.** `AIProviderName` (`core/utils/.../permission.ts`); the `AiProviderCredentials` union (`core/utils/.../ai-provider-credentials.ts`) — miss it and `aiProviderCredentials()` throws at run time, because `createLanguageModel`'s `never` check cannot see a provider the union never admits; `ProviderConfigUnion` (`core/shared/.../management/ai-providers`) — miss it and creating a key returns 400; `OpenAiCompatibleVendor`, `OPENAI_COMPATIBLE_VENDOR_BASE_URLS`, `NO_IMAGE_GENERATION_PROVIDERS` and the exhaustive `AI_PROVIDER_CAPABILITIES` (`core/piece-types/.../ai-providers.ts`); the `createLanguageModel` switch; the exhaustive `aiProviders` registry (`server/api/.../ai/providers`); web `SUPPORTED_AI_PROVIDERS`, the API-key group in `provider-request.ts`, and the markdown translation key; `MODELS_DEV_PROVIDER` in `tools/scripts/sync-model-catalog.ts`; the two provider lists in `docs/admin-guide/guides/setup-ai-providers.mdx`; and a CDN logo. The AI piece no longer has its own factory: `ai-sdk.ts` / `buildLanguageModel` were deleted in #15495 and AI steps run in the worker through `createLanguageModel`. `NO_IMAGE_GENERATION_PROVIDERS` is still load-bearing for text-only vendors, because `createImageModel` returns `undefined` for them and that list is what turns an image request into a clear error. Core libraries resolve each other from `dist`, so rebuild `core-utils` and `core-piece-types` (`npm run build` in each) before running a dependent package's tests, or the new enum value reads as `undefined`.- **Overriding `fetch` on a provider silently switches off key-health reporting.** `...observed` *is* a `fetch` (`observedProviderFetch`), so any later `fetch` in the same options object replaces it rather than adding to it — spread order decides, and nothing errors or logs. A path that needs its own `fetch` (the Responses header-stripping one, the Cloudflare gateway's `Authorization`-deleting one) must take `observedProviderFetch(options.onOutcome)` as a delegate and call it, not call `globalThis.fetch`. Resolve the delegate at call time rather than capturing it at model-construction time; late binding is both more correct and the only way a test can stub the global. This is the same family as the merge hazard above — the failure is always one provider, or one path within a provider, quietly not reporting.- **A provider branch merges cleanly and still opts out of whatever the switch gained meanwhile.** `createLanguageModel` applies cross-cutting behaviour by spreading it into *every* case — `...observed` (`observedProviderFetch`, added by the key-health work) is the current one. Git treats a long-lived branch's new `case` as an added block, so it lands with none of the spreads its siblings picked up, and the merge reports no conflict: the new provider is simply the one that never reports health. Nothing fails, nothing logs. After merging main into any provider branch, diff your `case` against a neighbouring one and check the spreads match, rather than trusting a clean merge.- **Only two `Record<AIProviderName, …>` maps are exhaustive, so the enum addition barely fights back.** `AI_PROVIDER_CAPABILITIES` (piece-types) and `aiProviders` (`ai/providers/index.ts`) must gain an entry; `PROVIDER_CREDENTIAL_FIELDS`, `ALLOWED_CHAT_MODELS_BY_PROVIDER`, `PROVIDER_MAX_CONTEXT_TOKENS`, `EMBEDDING_MODELS` and `WEB_SEARCH_MODE_BY_PROVIDER` are all `Partial<Record<…>>` and degrade silently to defaults. `grep -rn 'Record<AIProviderName' | grep -v 'Partial<'` is the whole compile-time safety net — every other consequence of a new provider is a runtime question you have to reason about yourself.@@ -265,4 +265,6 @@ Paths verified 2026-07-26.- **`OPENROUTER_PROVISION_KEY` is a management key and cannot make inference calls; only the per-platform keys it mints can.** OpenRouter states it outright: management keys are for creating, listing, updating and deleting other keys and are rejected by every completion or decisions endpoint. So "we already have an OpenRouter key" is true for provisioning and false for anything that needs to call a model at the instance level (the AI Router's Jev call, for example): that needs an ordinary inference key from the same account, created in the dashboard or via the same `POST /keys` the instance already uses, with a credit `limit`. The AI Router does exactly that since 2026-09-23: it runs on the platform's managed key where credits are on, else the admin's own OpenRouter row, as a worker `EXECUTE_AI` job billed like any AI step.- **`z.enum(SomeTsEnum).exclude([SomeTsEnum.MEMBER])` compiles and excludes nothing at the type level; pass the key string, `.exclude(['MEMBER'])`.** zod's `exclude` is typed over `keyof T` and returns `ZodEnum<Omit<T, U[number]>>`. A TS enum member is its own literal type, not the string `'MEMBER'`, so `Omit` finds no key to drop and the inferred value type keeps every member, while the runtime check does exclude it. The symptom is one step removed from the cause: a switch over the parsed field is suddenly non-exhaustive (`switch-exhaustiveness-check` in lint, `TS2366` in the build) even though the branch you removed can never arrive. `/v1/ai/execute` hit this when `ROUTE` was carved out of `AiStepAction` for #15707. Neither vitest nor a package-local eslint run without type information reports it; only the build does.- **The managed Activepieces row can never restrict its models, so a finding that the managed picker offers a model the key forbids is not reachable.** The row is inserted with `modelScope: 'all', modelIds: []`, `create()` refuses `provider === ACTIVEPIECES` (`aiProvider.activepiecesIsManaged`), and `update()` handles only `enabledForChat` for it and returns before any scope field is read (`ai-provider-service.ts`). Every published tier therefore runs on it, and any `modelScope` filtering on the managed path is inert. Reviewers (Greptile on #15871) raise this as a P1; answer with these three facts rather than adding a filter.-- **OpenAI and Azure language models run on the Responses API with `store: false`; everything else OpenAI-shaped stays on Chat Completions.** `createLanguageModel` builds OpenAI and Azure with `.responses()`. A Cloudflare Gateway `openai/*` text model goes to the gateway's `/openai` endpoint with `.responses()` on **both** routes: chat and agents use `routing: 'compat'`, which otherwise sends everything to `/compat/chat/completions`, so the OpenAI check has to sit before the compat early return. `withoutServerStorage` wraps them so `store: false` is the default. Chat Completions refuses tools + reasoning from gpt-5.4 on, and the gpt-5.6 family needs Responses for agents and chat (GIT-1848). `store: false` matters because the default `true` makes the SDK replay saved history as `item_reference` ids, which break after OpenAI's 30-day retention, on a key switch, or when compaction drops parts. Azure's Responses model reads `providerOptions.azure` and only falls back to `openai` when that key is absent, so set options under the provider's own key. The vendors (xAI, DeepSeek, ...), Mistral, every non-OpenAI model on the Cloudflare compat route, and Custom keep Chat Completions, because many of them only speak it. Custom offers Responses through `apiStyle: 'responses'`. To test `store: false`, give the saved assistant turn a **text** part with an `itemId`. With `store: true` the SDK swaps only text, reasoning and provider-run tool parts for `item_reference`, and plain function tool calls are always sent in full, so a tool-call-only fixture passes either way.+- **OpenAI, Azure and Meta language models run on the Responses API with `store: false`; everything else OpenAI-shaped stays on Chat Completions.** New OpenAI-shaped vendors default to Responses whenever their API serves an OpenAI-compatible `/responses` (Meta's does; NVIDIA's hosted API serves only `/chat/completions`, so NVIDIA stays on chat). `createLanguageModel` builds OpenAI and Azure with `.responses()`. A Cloudflare Gateway `openai/*` text model goes to the gateway's `/openai` endpoint with `.responses()` on **both** routes: chat and agents use `routing: 'compat'`, which otherwise sends everything to `/compat/chat/completions`, so the OpenAI check has to sit before the compat early return. `withoutServerStorage` wraps them so `store: false` is the default. Chat Completions refuses tools + reasoning from gpt-5.4 on, and the gpt-5.6 family needs Responses for agents and chat (GIT-1848). `store: false` matters because the default `true` makes the SDK replay saved history as `item_reference` ids, which break after OpenAI's 30-day retention, on a key switch, or when compaction drops parts. Azure's Responses model reads `providerOptions.azure` and only falls back to `openai` when that key is absent, so set options under the provider's own key. The vendors (xAI, DeepSeek, ...), Mistral, every non-OpenAI model on the Cloudflare compat route, and Custom keep Chat Completions, because many of them only speak it. Custom offers Responses through `apiStyle: 'responses'`. To test `store: false`, give the saved assistant turn a **text** part with an `itemId`. With `store: true` the SDK swaps only text, reasoning and provider-run tool parts for `item_reference`, and plain function tool calls are always sent in full, so a tool-call-only fixture passes either way.+- **Meta's Model API accepts only `tool_choice: auto`; anything else is a 400.** Two callers force a tool choice: Extract structured data (`required`) and the agent's last step (a named tool, or `none`). `createLanguageModel` wraps Meta in `autoToolChoiceOnly`, which sends `required` as `auto`, a named tool as `auto` with only that tool offered, and `none` as no tools. `auto` alone lets the model answer in text, so a forced call also gets an instruction naming the tool and one retry when the reply has no tool call, and a second text reply throws `ForcedToolNotCalledError` so callers fail instead of completing without the tool output; a forced streamed call (the agent's last step) is served from that retried generate call through `simulateStreamingMiddleware`. Any middleware that calls the model more than once must return the summed `usage` of every attempt (`addUsage` there): `billedLanguageModel` bills only the usage on the returned result, so a dropped attempt is unbilled spend. A middleware that throws after spending tokens has to carry the usage on its error the way `ForcedToolNotCalledError` does, and `reportFailedAttempts` in `activepieces-ai-cost.ts` must recognise it (by `name` and a `usage` field), or the failed call is never billed. Do not `import` the error class into `server-utils`: CI installs two copies of `[email protected]` with different peer hashes, and pulling `ai-providers`' types in first makes the global `AI_SDK_TELEMETRY_INTEGRATIONS` come from the other copy, which fails the `server-utils` build in `agent-ai-utils.ts` (it passes locally, where bun dedupes them). Reuse it for any vendor with the same limit rather than patching callers. The Llama API (`api.llama.com`) that predates it shut down on 2026-07-06; Meta now means the Muse models on `api.meta.ai/v1`.+- **NVIDIA's hosted keys (build.nvidia.com) are for trial and development only, and its `/models` lists classifiers next to chat models.** NVIDIA's terms forbid production use of the hosted catalogue (about 40 RPM, no paid tier), so production users run NIM themselves and connect it through Other (OpenAI Compatible). The catalogue's ids carry no capability field, so the `guard`, `safety`, `reward`, `parse`, `clip`, `detector`, `calibration` and `deplot` fragments in `NON_CHAT_MODEL_ID_FRAGMENTS` are what keep guard, reward and parser models out of chat pickers.diff --git a/bun.lock b/bun.lockindex cee12041f68..035420194b1 100644--- a/bun.lock+++ b/bun.lock@@ -100,7 +100,7 @@},"packages/core/ai-providers": {"name": "@activepieces/ai-providers",- "version": "0.3.0",+ "version": "0.4.0","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",@@ -154,7 +154,7 @@},"packages/core/piece-types": {"name": "@activepieces/core-piece-types",- "version": "0.12.3",+ "version": "0.13.0","dependencies": {"@activepieces/core-utils": "workspace:*","tslib": "2.6.2",@@ -167,7 +167,7 @@},"packages/core/shared": {"name": "@activepieces/shared",- "version": "0.212.0",+ "version": "0.213.0","dependencies": {"@activepieces/core-execution": "workspace:*","@activepieces/core-formula": "workspace:*",@@ -190,7 +190,7 @@},"packages/core/utils": {"name": "@activepieces/core-utils",- "version": "0.11.0",+ "version": "0.12.0","dependencies": {"deepmerge-ts": "8.0.2","ipaddr.js": "2.3.0",@@ -350,7 +350,7 @@},"packages/pieces/community/ai": {"name": "@activepieces/piece-ai",- "version": "0.15.0",+ "version": "0.15.1","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",diff --git a/docs/admin-guide/guides/setup-ai-providers.mdx b/docs/admin-guide/guides/setup-ai-providers.mdxindex 2a746afa06b..a6da457ea1c 100644--- a/docs/admin-guide/guides/setup-ai-providers.mdx+++ b/docs/admin-guide/guides/setup-ai-providers.mdx@@ -51,6 +51,7 @@ Once configured, the provider can be used by supported AI features in Activepiec* Z.ai* MiniMax* Moonshot AI+ * Meta</div><div>@@ -58,6 +59,7 @@ Once configured, the provider can be used by supported AI features in Activepiec* Azure* AWS Bedrock+ * NVIDIA**Gateways**@@ -100,6 +102,7 @@ Spend on your own key goes to your provider, so put a gateway in front of it whe* Z.ai* MiniMax* Moonshot AI+ * Meta</div><div>@@ -107,6 +110,7 @@ Spend on your own key goes to your provider, so put a gateway in front of it whe* Azure* AWS Bedrock+ * NVIDIA**Gateways**diff --git a/packages/core/ai-providers/package.json b/packages/core/ai-providers/package.jsonindex 720780e5f39..937765c7e6f 100644--- a/packages/core/ai-providers/package.json+++ b/packages/core/ai-providers/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/ai-providers",- "version": "0.3.0",+ "version": "0.4.0","type": "commonjs","sideEffects": false,"main": "./dist/src/index.js",diff --git a/packages/core/ai-providers/src/lib/create-language-model.test.ts b/packages/core/ai-providers/src/lib/create-language-model.test.tsindex 8c057af516d..2b4eb137c90 100644--- a/packages/core/ai-providers/src/lib/create-language-model.test.ts+++ b/packages/core/ai-providers/src/lib/create-language-model.test.ts@@ -85,6 +85,61 @@ const buildFor = (provider: AIProviderName, options?: Record<string, unknown>) =const supportedProviders = Object.values(AIProviderName).filter((p) => p !== AIProviderName.CLOUDFLARE_GATEWAY)+const forcedCall = {+ tools: [{ type: 'function' as const, name: 'extractData', inputSchema: { type: 'object' as const, properties: {} } }],+ toolChoice: { type: 'tool' as const, toolName: 'extractData' },+ prompt: [{ role: 'user' as const, content: [{ type: 'text' as const, text: 'hi' }] }],+}++async function replyingWith<T>({ replies, send }: {+ replies: Record<string, unknown>[]+ send: (model: ReturnType<typeof createLanguageModel>) => Promise<T>+}): Promise<{ bodies: Record<string, unknown>[], result: T }> {+ const original = globalThis.fetch+ const bodies: Record<string, unknown>[] = []+ globalThis.fetch = (_input, init) => {+ bodies.push(typeof init?.body === 'string' ? JSON.parse(init.body) : {})+ const reply = replies[Math.min(bodies.length - 1, replies.length - 1)]+ return Promise.resolve(new Response(JSON.stringify(reply), { headers: { 'content-type': 'application/json' } }))+ }+ try {+ const result = await send(buildFor(AIProviderName.META))+ return { bodies, result }+ }+ finally {+ globalThis.fetch = original+ }+}++async function readStream(stream: ReadableStream<{ type: string }>): Promise<{ type: string }[]> {+ const parts: { type: string }[] = []+ const reader = stream.getReader()+ for (let next = await reader.read(); !next.done; next = await reader.read()) {+ parts.push(next.value)+ }+ return parts+}++const RESPONSE_BASE = {+ id: 'resp_1',+ object: 'response',+ created_at: 1,+ model: 'muse-spark-1.3',+ status: 'completed',+ incomplete_details: null,+ usage: { input_tokens: 1, output_tokens: 1, input_tokens_details: { cached_tokens: 0 }, output_tokens_details: { reasoning_tokens: 0 } },+}++const TEXT_REPLY = {+ ...RESPONSE_BASE,+ output: [{ type: 'message', id: 'msg_1', role: 'assistant', status: 'completed', content: [{ type: 'output_text', text: 'Here is the data.', annotations: [] }] }],+}++const TOOL_REPLY = {+ ...RESPONSE_BASE,+ output: [{ type: 'function_call', id: 'fc_1', call_id: 'call_1', name: 'extractData', arguments: '{}', status: 'completed' }],+}+describe('AIProviderConfig union', () => {it('keeps every Vertex field instead of losing them to a looser member', () => {const config = {@@ -134,13 +189,123 @@ describe('createLanguageModel', () => {expect(headers.has('x-amz-security-token')).toBe(false)})- it.each([AIProviderName.OPENAI, AIProviderName.AZURE])('sends %s to the Responses API without storing the conversation', async (provider) => {+ it.each([AIProviderName.OPENAI, AIProviderName.AZURE, AIProviderName.META])('sends %s to the Responses API without storing the conversation', async (provider) => {const request = await generateHi(buildFor(provider))expect(new URL(request.url).pathname).toMatch(/\/responses$/)expect(request.body.store).toBe(false)})+ it('sends Meta to the Meta Model API and NVIDIA to the NVIDIA chat completions endpoint', async () => {+ const meta = await generateHi(buildFor(AIProviderName.META))+ const nvidia = await generateHi(buildFor(AIProviderName.NVIDIA))++ expect(meta.url).toBe('https://api.meta.ai/v1/responses')+ expect(meta.headers.get('authorization')).toBe('Bearer test-key')+ expect(nvidia.url).toBe('https://integrate.api.nvidia.com/v1/chat/completions')+ })++ describe('Meta, which only accepts tool_choice auto', () => {+ const tools = [+ { type: 'function' as const, name: 'extractData', inputSchema: { type: 'object' as const, properties: {} } },+ { type: 'function' as const, name: 'search', inputSchema: { type: 'object' as const, properties: {} } },+ ]+ const sendToMeta = (toolChoice: Parameters<ReturnType<typeof createLanguageModel>['doGenerate']>[0]['toolChoice']) => {+ const model = buildFor(AIProviderName.META)+ return captureSentRequest(() => model.doGenerate({ tools, toolChoice, prompt: [{ role: 'user', content: [{ type: 'text', text: 'hi' }] }] }))+ }+ const toolNames = (body: Record<string, unknown>) => (Array.isArray(body.tools) ? body.tools.map((tool: { name: string }) => tool.name) : [])++ it('turns required into auto and keeps every tool', async () => {+ const { body } = await sendToMeta({ type: 'required' })++ expect(body.tool_choice).toBe('auto')+ expect(toolNames(body)).toEqual(['extractData', 'search'])+ })++ it('turns a forced tool into auto with only that tool offered', async () => {+ const { body } = await sendToMeta({ type: 'tool', toolName: 'extractData' })++ expect(body.tool_choice).toBe('auto')+ expect(toolNames(body)).toEqual(['extractData'])+ })++ it('turns none into a request with no tools', async () => {+ const { body } = await sendToMeta({ type: 'none' })++ expect(body.tools).toBeUndefined()+ expect(body.tool_choice).toBeUndefined()+ })++ it('leaves auto alone', async () => {+ const { body } = await sendToMeta({ type: 'auto' })++ expect(body.tool_choice).toBe('auto')+ expect(toolNames(body)).toEqual(['extractData', 'search'])+ })++ it('tells the model to call the forced tool', async () => {+ const { body } = await sendToMeta({ type: 'tool', toolName: 'extractData' })++ expect(JSON.stringify(body.input)).toContain('Reply only by calling the extractData tool')+ })++ it('asks once more when the model answers a forced call in text', async () => {+ const { bodies, result } = await replyingWith({ replies: [TEXT_REPLY, TOOL_REPLY], send: (model) => model.doGenerate(forcedCall) })++ expect(bodies).toHaveLength(2)+ expect(JSON.stringify(bodies[1].input)).toContain('Your previous reply did not call a tool')+ expect(result.content).toContainEqual(expect.objectContaining({ type: 'tool-call', toolName: 'extractData' }))+ })++ it('fails instead of completing when the model answers in text twice', async () => {+ const { bodies, result } = await replyingWith({+ replies: [TEXT_REPLY, TEXT_REPLY],+ send: (model) => model.doGenerate(forcedCall).then(() => 'completed', (error: Error) => error.message),+ })++ expect(bodies).toHaveLength(2)+ expect(result).toBe('The model answered in text twice instead of calling the extractData tool')+ })++ it('fails a forced streamed call when the model answers in text twice', async () => {+ const { result } = await replyingWith({+ replies: [TEXT_REPLY, TEXT_REPLY],+ send: (model) => model.doStream(forcedCall).then(() => 'completed', (error: Error) => error.name),+ })++ expect(result).toBe('ForcedToolNotCalledError')+ })++ it('counts the tokens of both attempts when it asks again', async () => {+ const { result } = await replyingWith({ replies: [TEXT_REPLY, TOOL_REPLY], send: (model) => model.doGenerate(forcedCall) })++ expect(result.usage.inputTokens.total).toBe(2)+ expect(result.usage.outputTokens.total).toBe(2)+ })++ it('does not ask again once the model calls the tool', async () => {+ const { bodies, result } = await replyingWith({ replies: [TOOL_REPLY], send: (model) => model.doGenerate(forcedCall) })++ expect(bodies).toHaveLength(1)+ expect(result.content).toContainEqual(expect.objectContaining({ type: 'tool-call', toolName: 'extractData' }))+ })++ it('serves a forced streamed call from the retried generate call', async () => {+ const { bodies, result } = await replyingWith({+ replies: [TEXT_REPLY, TOOL_REPLY],+ send: async (model) => {+ const { stream } = await model.doStream(forcedCall)+ return readStream(stream)+ },+ })++ expect(bodies).toHaveLength(2)+ expect(bodies.every((body) => body.stream !== true)).toBe(true)+ expect(result).toContainEqual(expect.objectContaining({ type: 'tool-call', toolName: 'extractData' }))+ })+ })+it.each([{ provider: AIProviderName.OPENAI, optionsKey: 'openai' },{ provider: AIProviderName.AZURE, optionsKey: 'azure' },diff --git a/packages/core/ai-providers/src/lib/create-language-model.ts b/packages/core/ai-providers/src/lib/create-language-model.tsindex 0503b6c65c1..765e0ab475c 100644--- a/packages/core/ai-providers/src/lib/create-language-model.ts+++ b/packages/core/ai-providers/src/lib/create-language-model.ts@@ -1,4 +1,4 @@-import { AiProviderCredentials, AIProviderName, observedProviderFetch, ProviderOutcomeReporter, spreadIfDefined } from '@activepieces/core-utils'+import { AiProviderCredentials, AIProviderName, isNil, observedProviderFetch, ProviderOutcomeReporter, spreadIfDefined } from '@activepieces/core-utils'import { OPENAI_COMPATIBLE_VENDOR_BASE_URLS } from '@activepieces/core-piece-types'import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock'import { createVertex } from '@ai-sdk/google-vertex'@@ -10,7 +10,7 @@ import { createGoogleGenerativeAI } from '@ai-sdk/google'import { createOpenAI } from '@ai-sdk/openai'import { createOpenAICompatible } from '@ai-sdk/openai-compatible'import { createOpenRouter, OpenRouterChatSettings } from '@openrouter/ai-sdk-provider'-import { defaultSettingsMiddleware, ImageModel, LanguageModel, wrapLanguageModel } from 'ai'+import { defaultSettingsMiddleware, ImageModel, LanguageModel, LanguageModelMiddleware, simulateStreamingMiddleware, wrapLanguageModel } from 'ai'const VERTEX_MAAS_SUFFIX = '-maas'const VERTEX_ANTHROPIC_PREFIX = 'claude'@@ -83,7 +83,8 @@ export function createLanguageModel({ credentials, modelId, options = {} }: Creacase AIProviderName.ZAI:case AIProviderName.QWEN:case AIProviderName.MINIMAX:- case AIProviderName.MOONSHOT: {+ case AIProviderName.MOONSHOT:+ case AIProviderName.NVIDIA: {const { apiKey } = credentials.authreturn createOpenAICompatible({name: credentials.provider,@@ -92,6 +93,14 @@ export function createLanguageModel({ credentials, modelId, options = {} }: Crea...observed,}).chatModel(modelId)}+ case AIProviderName.META: {+ const { apiKey } = credentials.auth+ const responses = createOpenAI({ baseURL: OPENAI_COMPATIBLE_VENDOR_BASE_URLS[AIProviderName.META], apiKey, ...observed }).responses(modelId)+ return withoutServerStorage({+ model: wrapLanguageModel({ model: responses, middleware: autoToolChoiceOnly }),+ providerOptionsName: 'openai',+ })+ }case AIProviderName.OPENROUTER:case AIProviderName.ACTIVEPIECES: {const { apiKey } = credentials.auth@@ -189,6 +198,93 @@ export function withoutServerStorage({ model, providerOptionsName }: {})}+const autoToolChoiceOnly: LanguageModelMiddleware = {+ wrapGenerate: async ({ params, model }) => generateWithAutoToolChoice({ params, model }),+ wrapStream: async ({ params, model, doStream }) => {+ const { toolChoice } = params+ if (isNil(toolChoice) || toolChoice.type === 'auto') {+ return doStream()+ }+ if (toolChoice.type === 'none') {+ return model.doStream(withoutTools({ params }))+ }+ return simulatedStreaming.wrapStream!({+ params,+ model,+ doStream,+ doGenerate: () => generateWithAutoToolChoice({ params, model }),+ })+ },+}++async function generateWithAutoToolChoice({ params, model }: MiddlewareCall): Promise<GenerateResult> {+ const { toolChoice, tools } = params+ if (isNil(toolChoice) || toolChoice.type === 'auto') {+ return model.doGenerate(params)+ }+ if (toolChoice.type === 'none') {+ return model.doGenerate(withoutTools({ params }))+ }+ const toolName = toolChoice.type === 'tool' ? toolChoice.toolName : undefined+ const relaxed: MiddlewareCall['params'] = {+ ...params,+ tools: isNil(toolName) ? tools : tools?.filter((tool) => tool.name === toolName),+ toolChoice: { type: 'auto' },+ }+ const first = await model.doGenerate(withToolInstruction({ params: relaxed, toolName, retry: false }))+ if (callsATool({ result: first })) {+ return first+ }+ const retried = await model.doGenerate(withToolInstruction({ params: relaxed, toolName, retry: true }))+ const usage = addUsage({ a: first.usage, b: retried.usage })+ if (!callsATool({ result: retried })) {+ throw new ForcedToolNotCalledError({ toolName, usage })+ }+ return { ...retried, usage }+}++function addUsage({ a, b }: { a: GenerateResult['usage'], b: GenerateResult['usage'] }): GenerateResult['usage'] {+ return {+ inputTokens: {+ total: addCounts({ a: a.inputTokens.total, b: b.inputTokens.total }),+ noCache: addCounts({ a: a.inputTokens.noCache, b: b.inputTokens.noCache }),+ cacheRead: addCounts({ a: a.inputTokens.cacheRead, b: b.inputTokens.cacheRead }),+ cacheWrite: addCounts({ a: a.inputTokens.cacheWrite, b: b.inputTokens.cacheWrite }),+ },+ outputTokens: {+ total: addCounts({ a: a.outputTokens.total, b: b.outputTokens.total }),+ text: addCounts({ a: a.outputTokens.text, b: b.outputTokens.text }),+ reasoning: addCounts({ a: a.outputTokens.reasoning, b: b.outputTokens.reasoning }),+ },+ ...spreadIfDefined('raw', b.raw),+ }+}++function addCounts({ a, b }: { a: number | undefined, b: number | undefined }): number | undefined {+ return isNil(a) && isNil(b) ? undefined : (a ?? 0) + (b ?? 0)+}++function callsATool({ result }: { result: GenerateResult }): boolean {+ return result.content.some((part) => part.type === 'tool-call')+}++function withoutTools({ params }: { params: MiddlewareCall['params'] }): MiddlewareCall['params'] {+ return { ...params, tools: undefined, toolChoice: undefined }+}++function withToolInstruction({ params, toolName, retry }: {+ params: MiddlewareCall['params']+ toolName: string | undefined+ retry: boolean+}): MiddlewareCall['params'] {+ const target = isNil(toolName) ? 'one of the available tools' : `the ${toolName} tool`+ const reminder = retry ? 'Your previous reply did not call a tool. ' : ''+ return {+ ...params,+ prompt: [...params.prompt, { role: 'system', content: `${reminder}Reply only by calling ${target}. Do not reply with text.` }],+ }+}+function createOpenRouterChatModel({ apiKey, modelId, options }: {apiKey: string | undefinedmodelId: string@@ -214,6 +310,24 @@ export function buildOpenAICompatibleHeaders({ apiKeyHeader, apiKey, defaultHead}}+const simulatedStreaming = simulateStreamingMiddleware()++class ForcedToolNotCalledError extends Error {+ readonly usage: GenerateResult['usage']++ constructor({ toolName, usage }: { toolName: string | undefined, usage: GenerateResult['usage'] }) {+ super(isNil(toolName)+ ? 'The model answered in text twice instead of calling a tool'+ : `The model answered in text twice instead of calling the ${toolName} tool`)+ this.name = 'ForcedToolNotCalledError'+ this.usage = usage+ }+}++type MiddlewareCall = Pick<Parameters<NonNullable<LanguageModelMiddleware['wrapGenerate']>>[0], 'params' | 'model'>++type GenerateResult = Awaited<ReturnType<MiddlewareCall['model']['doGenerate']>>+export type LanguageModelOptions = {onOutcome?: ProviderOutcomeReporteropenRouterSettings?: OpenRouterChatSettingsdiff --git a/packages/core/piece-types/package.json b/packages/core/piece-types/package.jsonindex 27a81220c18..ab04524b72d 100644--- a/packages/core/piece-types/package.json+++ b/packages/core/piece-types/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/core-piece-types",- "version": "0.12.3",+ "version": "0.13.0","type": "commonjs","main": "./dist/src/index.js","scripts": {diff --git a/packages/core/piece-types/src/lib/ai-providers.test.ts b/packages/core/piece-types/src/lib/ai-providers.test.tsindex 74b63f2fdf9..bca0fdbe40b 100644--- a/packages/core/piece-types/src/lib/ai-providers.test.ts+++ b/packages/core/piece-types/src/lib/ai-providers.test.ts@@ -22,6 +22,8 @@ describe('AI_PROVIDER_CAPABILITIES', () => {AIProviderName.QWEN,AIProviderName.MINIMAX,AIProviderName.MOONSHOT,+ AIProviderName.META,+ AIProviderName.NVIDIA,].sort())})@@ -203,6 +205,20 @@ describe('aiProviderUtils.isChatModelId', () => {expect(isChat(modelId)).toBe(false)})+ it.each([+ 'meta/llama-guard-4-12b',+ 'nvidia/llama-3.1-nemoguard-8b-content-safety',+ 'nvidia/nemotron-3.5-content-safety',+ 'nvidia/nemotron-4-340b-reward',+ 'nvidia/nemotron-parse',+ 'nvidia/nvclip',+ 'nvidia/ai-synthetic-video-detector',+ 'nvidia/ising-calibration-1.5-31b',+ 'google/deplot',+ ])('rejects %s, an NVIDIA catalogue model that classifies or parses rather than chats', (modelId) => {+ expect(isChat(modelId)).toBe(false)+ })+it.each(['gpt-4o','gpt-4.1-mini',@@ -211,6 +227,9 @@ describe('aiProviderUtils.isChatModelId', () => {'gemini-2.5-pro','deepseek-chat','kimi-k2',+ 'muse-spark-1.3',+ 'nvidia/nemotron-3-super-120b-a12b',+ 'openai/gpt-oss-20b',])('accepts %s', (modelId) => {expect(isChat(modelId)).toBe(true)})diff --git a/packages/core/piece-types/src/lib/ai-providers.ts b/packages/core/piece-types/src/lib/ai-providers.tsindex fc6796dd2fd..46f27db98b9 100644--- a/packages/core/piece-types/src/lib/ai-providers.ts+++ b/packages/core/piece-types/src/lib/ai-providers.ts@@ -382,6 +382,14 @@ const NON_CHAT_MODEL_ID_FRAGMENTS = ['moderation','speech','voice',+ 'guard',+ 'safety',+ 'reward',+ 'parse',+ 'clip',+ 'detector',+ 'calibration',+ 'deplot',]const NON_CHAT_MODEL_ID_TOKENS = ['tts', 'asr']@@ -400,6 +408,7 @@ const PROVIDER_MAX_CONTEXT_TOKENS: Partial<Record<AIProviderName, number>> = {[AIProviderName.OPENROUTER]: 128_000,[AIProviderName.ACTIVEPIECES]: 200_000,[AIProviderName.MISTRAL]: 128_000,+ [AIProviderName.META]: 1_048_576,}function getMaxContextTokens({ provider }: { provider: AIProviderName | undefined }): number {@@ -431,6 +440,8 @@ const NO_IMAGE_GENERATION_PROVIDERS = new Set<AIProviderName>([AIProviderName.QWEN,AIProviderName.MINIMAX,AIProviderName.MOONSHOT,+ AIProviderName.META,+ AIProviderName.NVIDIA,])export const OPENAI_COMPATIBLE_VENDOR_BASE_URLS: Record<OpenAiCompatibleVendor, string> = {@@ -440,6 +451,8 @@ export const OPENAI_COMPATIBLE_VENDOR_BASE_URLS: Record<OpenAiCompatibleVendor,[AIProviderName.QWEN]: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',[AIProviderName.MINIMAX]: 'https://api.minimax.io/v1',[AIProviderName.MOONSHOT]: 'https://api.moonshot.ai/v1',+ [AIProviderName.META]: 'https://api.meta.ai/v1',+ [AIProviderName.NVIDIA]: 'https://integrate.api.nvidia.com/v1',}function buildProviderCapabilities(provider: AIProviderName): AIProviderCapabilities {@@ -498,6 +511,8 @@ export const AI_PROVIDER_CAPABILITIES: Record<AIProviderName, AIProviderCapabili[AIProviderName.QWEN]: buildProviderCapabilities(AIProviderName.QWEN),[AIProviderName.MINIMAX]: buildProviderCapabilities(AIProviderName.MINIMAX),[AIProviderName.MOONSHOT]: buildProviderCapabilities(AIProviderName.MOONSHOT),+ [AIProviderName.META]: buildProviderCapabilities(AIProviderName.META),+ [AIProviderName.NVIDIA]: buildProviderCapabilities(AIProviderName.NVIDIA),}export const aiProviderUtils = {@@ -525,6 +540,8 @@ export type OpenAiCompatibleVendor =| AIProviderName.QWEN| AIProviderName.MINIMAX| AIProviderName.MOONSHOT+ | AIProviderName.META+ | AIProviderName.NVIDIAexport type AIProviderCapabilities = {chatModels?: readonly string[] | undefineddiff --git a/packages/core/shared/package.json b/packages/core/shared/package.jsonindex 72e263deb08..f981ca55b1d 100644--- a/packages/core/shared/package.json+++ b/packages/core/shared/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/shared",- "version": "0.212.0",+ "version": "0.213.0","type": "commonjs","sideEffects": false,"main": "./dist/src/index.js",diff --git a/packages/core/shared/src/lib/management/ai-providers/index.ts b/packages/core/shared/src/lib/management/ai-providers/index.tsindex cbeb02192d5..aba09f7e968 100644--- a/packages/core/shared/src/lib/management/ai-providers/index.ts+++ b/packages/core/shared/src/lib/management/ai-providers/index.ts@@ -106,6 +106,18 @@ const ProviderConfigUnion = z.discriminatedUnion('provider', [config: OpenAiCompatibleVendorConfig,auth: strictAuth(BaseAIProviderAuthConfig),}),+ z.object({+ displayName: z.string().min(1),+ provider: z.literal(AIProviderName.META),+ config: OpenAiCompatibleVendorConfig,+ auth: strictAuth(BaseAIProviderAuthConfig),+ }),+ z.object({+ displayName: z.string().min(1),+ provider: z.literal(AIProviderName.NVIDIA),+ config: OpenAiCompatibleVendorConfig,+ auth: strictAuth(BaseAIProviderAuthConfig),+ }),])const StrictAIProviderAuthConfig = z.union([diff --git a/packages/core/utils/package.json b/packages/core/utils/package.jsonindex 4d837e12730..e1d59fb02e4 100644--- a/packages/core/utils/package.json+++ b/packages/core/utils/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/core-utils",- "version": "0.11.0",+ "version": "0.12.0","type": "commonjs","main": "./dist/src/index.js","scripts": {diff --git a/packages/core/utils/src/lib/ai-provider-credentials.ts b/packages/core/utils/src/lib/ai-provider-credentials.tsindex 9c7e39414ae..b90b2a846de 100644--- a/packages/core/utils/src/lib/ai-provider-credentials.ts+++ b/packages/core/utils/src/lib/ai-provider-credentials.ts@@ -170,6 +170,8 @@ export const AiProviderCredentials = z.discriminatedUnion('provider', [z.object({ provider: z.literal(AIProviderName.QWEN), config: OpenAiCompatibleVendorConfig.partial(), auth: BaseAIProviderAuthConfig.partial() }),z.object({ provider: z.literal(AIProviderName.MINIMAX), config: OpenAiCompatibleVendorConfig.partial(), auth: BaseAIProviderAuthConfig.partial() }),z.object({ provider: z.literal(AIProviderName.MOONSHOT), config: OpenAiCompatibleVendorConfig.partial(), auth: BaseAIProviderAuthConfig.partial() }),+ z.object({ provider: z.literal(AIProviderName.META), config: OpenAiCompatibleVendorConfig.partial(), auth: BaseAIProviderAuthConfig.partial() }),+ z.object({ provider: z.literal(AIProviderName.NVIDIA), config: OpenAiCompatibleVendorConfig.partial(), auth: BaseAIProviderAuthConfig.partial() }),])export type AiProviderCredentials = z.infer<typeof AiProviderCredentials>diff --git a/packages/core/utils/src/lib/permission.ts b/packages/core/utils/src/lib/permission.tsindex 9eca6690d21..683370e5193 100644--- a/packages/core/utils/src/lib/permission.ts+++ b/packages/core/utils/src/lib/permission.ts@@ -64,4 +64,6 @@ export enum AIProviderName {QWEN = 'qwen',MINIMAX = 'minimax',MOONSHOT = 'moonshot',+ META = 'meta',+ NVIDIA = 'nvidia',}\ No newline at end of filediff --git a/packages/pieces/community/ai/package.json b/packages/pieces/community/ai/package.jsonindex 1cbe3e945ea..52c0fd88bb6 100644--- a/packages/pieces/community/ai/package.json+++ b/packages/pieces/community/ai/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/piece-ai",- "version": "0.15.0",+ "version": "0.15.1","type": "commonjs","main": "./dist/src/index.js","types": "./dist/src/index.d.ts",diff --git a/packages/server/api/src/app/ai/providers/index.ts b/packages/server/api/src/app/ai/providers/index.tsindex 27027e01f67..6b9792596cf 100644--- a/packages/server/api/src/app/ai/providers/index.ts+++ b/packages/server/api/src/app/ai/providers/index.ts@@ -30,6 +30,8 @@ export const aiProviders: Record<AIProviderName, AIProviderStrategy<AIProviderAu[AIProviderName.QWEN]: openAiCompatibleVendor({ name: 'Qwen', provider: AIProviderName.QWEN }),[AIProviderName.MINIMAX]: openAiCompatibleVendor({ name: 'MiniMax', provider: AIProviderName.MINIMAX }),[AIProviderName.MOONSHOT]: openAiCompatibleVendor({ name: 'Moonshot AI', provider: AIProviderName.MOONSHOT }),+ [AIProviderName.META]: openAiCompatibleVendor({ name: 'Meta', provider: AIProviderName.META }),+ [AIProviderName.NVIDIA]: openAiCompatibleVendor({ name: 'NVIDIA', provider: AIProviderName.NVIDIA }),[AIProviderName.ACTIVEPIECES]: {...openRouterProvider,name: 'Activepieces',diff --git a/packages/server/api/test/unit/app/ai/providers/openai-compatible-vendor.test.ts b/packages/server/api/test/unit/app/ai/providers/openai-compatible-vendor.test.tsindex 40aa721968b..b559e401c07 100644--- a/packages/server/api/test/unit/app/ai/providers/openai-compatible-vendor.test.ts+++ b/packages/server/api/test/unit/app/ai/providers/openai-compatible-vendor.test.ts@@ -45,6 +45,18 @@ describe('openAiCompatibleVendor', () => {expect(requestedUrl()).toBe('https://api.z.ai/api/paas/v4/models')})+ it.each([+ { provider: AIProviderName.META, url: 'https://api.meta.ai/v1/models' },+ { provider: AIProviderName.NVIDIA, url: 'https://integrate.api.nvidia.com/v1/models' },+ ])('lists $provider models from its own endpoint', async ({ provider, url }) => {+ respondWith(['some-model'])+ const vendor = openAiCompatibleVendor({ name: provider, provider })++ await vendor.listModels({ apiKey: 'k' }, {})++ expect(requestedUrl()).toBe(url)+ })+it('authenticates with the configured key', async () => {respondWith(['deepseek-chat'])const vendor = openAiCompatibleVendor({ name: 'DeepSeek', provider: AIProviderName.DEEPSEEK })diff --git a/packages/server/utils/src/activepieces-ai-cost.ts b/packages/server/utils/src/activepieces-ai-cost.tsindex 732014d2a37..8768f02e393 100644--- a/packages/server/utils/src/activepieces-ai-cost.ts+++ b/packages/server/utils/src/activepieces-ai-cost.ts@@ -1,4 +1,4 @@-import { ActivepiecesAiBilling, ActivepiecesAiCall, ActivepiecesAiConsumerSource, ActivepiecesAiCostReporter, AiCallTokens, AiCharge, AiChargeBasis, AIProviderName, isNil, spreadIfDefined } from '@activepieces/core-utils'+import { ActivepiecesAiBilling, ActivepiecesAiCall, ActivepiecesAiConsumerSource, ActivepiecesAiCostReporter, AiCallTokens, AiCharge, AiChargeBasis, AIProviderName, isNil, spreadIfDefined, tryCatch } from '@activepieces/core-utils'import { EmbeddingModelV4Result, isJSONObject, LanguageModelV4GenerateResult, LanguageModelV4StreamPart, LanguageModelV4StreamResult, LanguageModelV4Usage, SharedV4ProviderMetadata } from '@ai-sdk/provider'import { EmbeddingModel, LanguageModel, wrapEmbeddingModel, wrapLanguageModel } from 'ai'import { z } from 'zod'@@ -70,14 +70,24 @@ function billingContextOf({ provider, providerConfigId, modelId, billing, charge}async function billGenerate({ doGenerate, context }: BillGenerateParams): Promise<LanguageModelV4GenerateResult> {- const result = await doGenerate()+ const attempt = await tryCatch(async () => doGenerate())+ if (attempt.error !== null) {+ reportFailedAttempts({ context, error: attempt.error })+ throw attempt.error+ }+ const result = attempt.dataconst generationId = result.response?.idreport({ context, generationId, call: createBillingInfo({ context, generationId, providerMetadata: result.providerMetadata, usage: result.usage, headers: result.response?.headers }), tokens: tokensOf(result.usage) })return result}async function billStream({ doStream, context }: BillStreamParams): Promise<LanguageModelV4StreamResult> {- const { stream, ...rest } = await doStream()+ const attempt = await tryCatch(async () => doStream())+ if (attempt.error !== null) {+ reportFailedAttempts({ context, error: attempt.error })+ throw attempt.error+ }+ const { stream, ...rest } = attempt.datareturn { ...rest, stream: stream.pipeThrough(billedStream({ context, headers: rest.response?.headers })) }}@@ -155,6 +165,17 @@ async function recoverCostAndReport({ state, context }: SettleStreamParams): Pro})}+function reportFailedAttempts({ context, error }: { context: BillingContext, error: Error }): void {+ if (!isForcedToolFailure(error)) {+ return+ }+ report({ context, call: createBillingInfo({ context, generationId: undefined, providerMetadata: undefined, usage: error.usage }), tokens: tokensOf(error.usage) })+}++function isForcedToolFailure(error: Error): error is Error & { usage: LanguageModelV4Usage } {+ return error.name === FORCED_TOOL_NOT_CALLED_ERROR && 'usage' in error+}+function createBillingInfo({ context, generationId, providerMetadata, usage, headers }: CreateBillingInfoParams): ActivepiecesAiCall | undefined {const costUsd = openRouterCostOf(providerMetadata) ?? gatewayHeaderCostOf({ provider: context.provider, headers })const tokens = { ...tokensOf(usage), observedCostUsd: costUsd }@@ -262,6 +283,8 @@ function drainUnbilledCalls(): UnbilledCall[] {return drained}+const FORCED_TOOL_NOT_CALLED_ERROR = 'ForcedToolNotCalledError'+const EmbeddingResponseBody = z.object({id: z.string().min(1),})diff --git a/packages/server/utils/test/activepieces-ai-cost.test.ts b/packages/server/utils/test/activepieces-ai-cost.test.tsindex 663a309ff15..fcffc4143fc 100644--- a/packages/server/utils/test/activepieces-ai-cost.test.ts+++ b/packages/server/utils/test/activepieces-ai-cost.test.ts@@ -154,6 +154,31 @@ describe('what a model call reports back for billing', () => {})})+ it.each(['generate', 'stream'] as const)('bills the tokens of a forced tool call that failed after its retry (%s)', async (path) => {+ const usage = { inputTokens: { total: 9, noCache: 9, cacheRead: undefined, cacheWrite: undefined }, outputTokens: { total: 4, text: 4, reasoning: undefined } }+ const failure = Object.assign(new Error('The model answered in text twice instead of calling the extractData tool'), { name: 'ForcedToolNotCalledError', usage })+ const model = activepiecesAiCost.billedLanguageModel({+ model: {+ ...modelReturning({}),+ doGenerate: async () => Promise.reject(failure),+ doStream: async () => Promise.reject(failure),+ },+ provider: AIProviderName.META,+ modelId: 'muse-spark-1.3',+ billing: BILLING,+ charge: chargeFor({ provider: AIProviderName.META }),+ })+ if (typeof model === 'string') {+ throw new Error('expected a model object')+ }++ const outcome = await (path === 'generate' ? model.doGenerate({ prompt: [] }) : model.doStream({ prompt: [] })).then(() => 'completed', (error: Error) => error.name)++ expect(outcome).toBe('ForcedToolNotCalledError')+ expect(reported).toHaveLength(1)+ expect(reported[0].call).toMatchObject({ inputTokens: 9, outputTokens: 4 })+ })+it('bills a call on the customer own key at one fixed credit, whatever it cost us', async () => {const model = activepiecesAiCost.billedLanguageModel({model: modelReturning({diff --git a/packages/web/public/locales/en/translation.json b/packages/web/public/locales/en/translation.jsonindex f81c6f2e147..180dac4fc7c 100644--- a/packages/web/public/locales/en/translation.json+++ b/packages/web/public/locales/en/translation.json@@ -2868,6 +2868,8 @@"Follow these instructions to get your MiniMax API Key:\n\n1. Go to https://platform.minimax.io and sign in.\n2. Open **API Keys** in your account settings, create a key, and paste it below.\n\nThis connects to MiniMax's international endpoint. A key from the China platform will not authenticate here — add that account through **Other (OpenAI Compatible)** with your China base URL instead.\n": "Follow these instructions to get your MiniMax API Key:\n\n1. Go to https://platform.minimax.io and sign in.\n2. Open **API Keys** in your account settings, create a key, and paste it below.\n\nThis connects to MiniMax's international endpoint. A key from the China platform will not authenticate here — add that account through **Other (OpenAI Compatible)** with your China base URL instead.\n","Follow these instructions to get your Mistral AI API Key:\n\n1. Go to https://console.mistral.ai.\n2. Navigate to **API Keys** in your account settings.\n3. Click **Create new key**, copy the key, and paste it below.\n": "Follow these instructions to get your Mistral AI API Key:\n\n1. Go to https://console.mistral.ai.\n2. Navigate to **API Keys** in your account settings.\n3. Click **Create new key**, copy the key, and paste it below.\n","Follow these instructions to get your Moonshot AI (Kimi) API Key:\n\n1. Go to https://platform.moonshot.ai/console/api-keys.\n2. Click **Create API key**, copy the key, and paste it below.\n\nThis connects to Moonshot's international endpoint. A key from the China platform will not authenticate here — add that account through **Other (OpenAI Compatible)** with your China base URL instead.\n": "Follow these instructions to get your Moonshot AI (Kimi) API Key:\n\n1. Go to https://platform.moonshot.ai/console/api-keys.\n2. Click **Create API key**, copy the key, and paste it below.\n\nThis connects to Moonshot's international endpoint. A key from the China platform will not authenticate here — add that account through **Other (OpenAI Compatible)** with your China base URL instead.\n",+ "Follow these instructions to get your Meta Model API Key:\n\n1. Go to https://dev.meta.ai and sign in.\n2. Open **API keys** in the dashboard, click **Create API key**, copy the key, and paste it below.\n\nThe Meta Model API serves Meta's Muse models and opened to developers in the US first.\n": "Follow these instructions to get your Meta Model API Key:\n\n1. Go to https://dev.meta.ai and sign in.\n2. Open **API keys** in the dashboard, click **Create API key**, copy the key, and paste it below.\n\nThe Meta Model API serves Meta's Muse models and opened to developers in the US first.\n",+ "Follow these instructions to get your NVIDIA API Key:\n\n1. Go to https://build.nvidia.com and open any model.\n2. Click **Get API Key**, sign in with your NVIDIA account, copy the key (it starts with nvapi-), and paste it below.\n\nNVIDIA offers these hosted keys for trial and development use. For production, run NVIDIA NIM yourself and add it through **Other (OpenAI Compatible)** with your NIM base URL.\n": "Follow these instructions to get your NVIDIA API Key:\n\n1. Go to https://build.nvidia.com and open any model.\n2. Click **Get API Key**, sign in with your NVIDIA account, copy the key (it starts with nvapi-), and paste it below.\n\nNVIDIA offers these hosted keys for trial and development use. For production, run NVIDIA NIM yourself and add it through **Other (OpenAI Compatible)** with your NIM base URL.\n","Follow these instructions to get your OpenAI API Key:\n\n1. Go to https://platform.openai.com/account/api-keys.\n2. Once on the website, locate and click on the option to obtain your OpenAI API Key.\n\nIt is strongly recommended that you add your credit card information to your OpenAI account and upgrade to the paid plan **before** generating the API Key. This will help you prevent 429 errors.\n": "Follow these instructions to get your OpenAI API Key:\n\n1. Go to https://platform.openai.com/account/api-keys.\n2. Once on the website, locate and click on the option to obtain your OpenAI API Key.\n\nIt is strongly recommended that you add your credit card information to your OpenAI account and upgrade to the paid plan **before** generating the API Key. This will help you prevent 429 errors.\n","Follow these instructions to get your OpenRouter API Key:\n1. Go to https://openrouter.ai/settings/keys.\n2. Once on the website, locate and click on the option to obtain your OpenRouter API Key.": "Follow these instructions to get your OpenRouter API Key:\n1. Go to https://openrouter.ai/settings/keys.\n2. Once on the website, locate and click on the option to obtain your OpenRouter API Key.","Follow these instructions to get your Qwen API Key:\n\n1. Go to https://bailian.console.alibabacloud.com and sign in to Alibaba Cloud Model Studio.\n2. Open **API-KEY**, create a key, and paste it below.\n\nThis connects to Model Studio's international (Singapore) endpoint. A key from the Beijing region will not authenticate here — add that account through **Other (OpenAI Compatible)** with your China base URL instead.\n": "Follow these instructions to get your Qwen API Key:\n\n1. Go to https://bailian.console.alibabacloud.com and sign in to Alibaba Cloud Model Studio.\n2. Open **API-KEY**, create a key, and paste it below.\n\nThis connects to Model Studio's international (Singapore) endpoint. A key from the Beijing region will not authenticate here — add that account through **Other (OpenAI Compatible)** with your China base URL instead.\n",diff --git a/packages/web/src/app/routes/platform/setup/ai/providers-tab/provider-request.ts b/packages/web/src/app/routes/platform/setup/ai/providers-tab/provider-request.tsindex e01872e10d0..916852c9371 100644--- a/packages/web/src/app/routes/platform/setup/ai/providers-tab/provider-request.ts+++ b/packages/web/src/app/routes/platform/setup/ai/providers-tab/provider-request.ts@@ -90,6 +90,8 @@ function buildCreateRequest({case AIProviderName.QWEN:case AIProviderName.MINIMAX:case AIProviderName.MOONSHOT:+ case AIProviderName.META:+ case AIProviderName.NVIDIA:return {provider,displayName,diff --git a/packages/web/src/features/agents/ai-providers.ts b/packages/web/src/features/agents/ai-providers.tsindex a2a37ee2a7b..fb1f4e671c9 100644--- a/packages/web/src/features/agents/ai-providers.ts+++ b/packages/web/src/features/agents/ai-providers.ts@@ -79,6 +79,19 @@ export const SUPPORTED_AI_PROVIDERS: AiProviderInfo[] = [logoUrl: 'https://cdn.activepieces.com/pieces/google-gemini.png',dashboardUrl: 'https://aistudio.google.com/usage',},+ {+ provider: AIProviderName.META,+ name: 'Meta',+ logoUrl: 'https://cdn.activepieces.com/pieces/meta.png',+ markdown: t(`Follow these instructions to get your Meta Model API Key:++1. Go to https://dev.meta.ai and sign in.+2. Open **API keys** in the dashboard, click **Create API key**, copy the key, and paste it below.++The Meta Model API serves Meta's Muse models and opened to developers in the US first.+`),+ dashboardUrl: 'https://dev.meta.ai',+ },{provider: AIProviderName.MINIMAX,name: 'MiniMax',@@ -114,6 +127,18 @@ This connects to MiniMax's international endpoint. A key from the China platform2. Click **Create API key**, copy the key, and paste it below.This connects to Moonshot's international endpoint. A key from the China platform will not authenticate here — add that account through **Other (OpenAI Compatible)** with your China base URL instead.+`),+ },+ {+ provider: AIProviderName.NVIDIA,+ name: 'NVIDIA',+ logoUrl: 'https://cdn.activepieces.com/pieces/nvidia.png',+ markdown: t(`Follow these instructions to get your NVIDIA API Key:++1. Go to https://build.nvidia.com and open any model.+2. Click **Get API Key**, sign in with your NVIDIA account, copy the key (it starts with nvapi-), and paste it below.++NVIDIA offers these hosted keys for trial and development use. For production, run NVIDIA NIM yourself and add it through **Other (OpenAI Compatible)** with your NIM base URL.`),},{diff --git a/tools/scripts/sync-model-catalog.ts b/tools/scripts/sync-model-catalog.tsindex 7610040ea10..61e2d9e0d16 100644--- a/tools/scripts/sync-model-catalog.ts+++ b/tools/scripts/sync-model-catalog.ts@@ -25,6 +25,8 @@ const MODELS_DEV_PROVIDER: Partial<Record<AIProviderName, string>> = {[AIProviderName.QWEN]: 'alibaba',[AIProviderName.MINIMAX]: 'minimax',[AIProviderName.MOONSHOT]: 'moonshotai',+ [AIProviderName.META]: 'meta',+ [AIProviderName.NVIDIA]: 'nvidia',}const ALIASED_AT_LOOKUP: AIProviderName[] = [AIProviderName.ACTIVEPIECES]