← All @molecule/* packages · App templates
@molecule/api-ai-alibabaProvider bond · ai · API (Node) · v1.1.0 · Apache-2.0
Alibaba Qwen AI provider for molecule.dev
npm install @molecule/api-ai-alibabanpm · Source on GitHub · Implements @molecule/api-ai
@molecule/api-ai-alibaba is a provider bond on the API (Node) side: it implements the ai core interface (@molecule/api-ai) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
Works with: @molecule/api-bond, @molecule/api-i18n, @molecule/api-secrets
Secrets: DASHSCOPE_API_KEY
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Alibaba Qwen AI provider for molecule.dev.
provider
npm install @molecule/api-ai-alibaba @molecule/api-ai @molecule/api-bond @molecule/api-i18n @molecule/api-secrets
AlibabaConfigConfiguration for Alibaba Qwen.
interface AlibabaConfig {
/** Called on each rate-limited/overloaded upstream response, before any retry sleep. */
onRateLimit?: AiRateLimitCallback
/** API key. Defaults to the `DASHSCOPE_API_KEY` (or `ALIBABA_API_KEY`) env var. */
apiKey?: string
/** Default model. Defaults to 'qwen3.8-max'. */
defaultModel?: string
/** Maximum tokens for completions. */
maxTokens?: number
/**
* Base URL override (for proxies). Defaults to the `DASHSCOPE_BASE_URL` env
* var, then 'https://dashscope-us.aliyuncs.com/compatible-mode'.
*/
baseUrl?: string
/**
* Chat-completions path appended to {@link baseUrl}. Defaults to
* `/v1/chat/completions`. Unchanged for DashScope-US; also correct for
* DeepInfra when baseUrl='https://api.deepinfra.com/v1/openai' would need
* `/chat/completions` — set it accordingly for that host.
*/
completionsPath?: string
/**
* Catalog-id → upstream-model-id map, applied to the outbound request only, so
* a US host (DeepInfra) receives its namespaced id
* (`Qwen/Qwen3-Coder-480B-A35B-Instruct-Turbo`) while pricing/cost/display keep
* the canonical catalog id (`qwen3-coder-plus`).
*/
modelMap?: Record<string, string>
}
ProcessEnvProcess env vars read by the Alibaba DashScope AI bond.
interface ProcessEnv {
/** Alibaba DashScope API key. */
DASHSCOPE_API_KEY: string
/** Alternate key env var (same value; checked after DASHSCOPE_API_KEY). */
ALIBABA_API_KEY?: string
/** Base URL override (for credential brokers / gateways / US OpenAI-compatible hosts). */
DASHSCOPE_BASE_URL?: string
/** Chat-completions path override (see {@link AlibabaConfig.completionsPath}). */
DASHSCOPE_COMPLETIONS_PATH?: string
}
createProvider(config)Creates an Alibaba Qwen AI provider instance.
function createProvider(config?: AlibabaConfig): AIProvider
config — Alibaba-specific configuration (API key, model, max tokens, base URL).Returns: An AIProvider backed by the DashScope Chat Completions API.
aiAlibabaSecretDefinitionsSecret definitions required by the Alibaba DashScope AI bond.
const aiAlibabaSecretDefinitions: SecretDefinition[]
providerThe provider implementation.
const provider: AIProvider
Implements @molecule/api-ai interface.
Setup function to register this provider with the bond system:
import { bond } from '@molecule/api-bond'
import { provider } from '@molecule/api-ai-alibaba'
export function setupAiAlibaba(): void {
bond('ai', 'alibaba', provider)
}
Peer dependencies:
@molecule/api-ai ^1.0.1@molecule/api-bond ^1.0.1@molecule/api-i18n ^1.0.1@molecule/api-secrets ^1.0.1DASHSCOPE_API_KEY (required) — Alibaba DashScope API key
sk-...@molecule/api-ai@molecule/api-bond@molecule/api-i18n@molecule/api-secretsConfig: DASHSCOPE_API_KEY (or ALIBABA_API_KEY, SERVER-side only) plus an optional default
model id/base URL.
Missing key fails fast: the provider throws naming both accepted env vars on first use
(the exported provider is a lazy proxy, so this fires on the first chat() call, not at
bond/module-load time) — it never silently sends an empty key.
Error message disambiguation: a plain 400 that ISN'T a context-length/invalid-param error already handled above gets its own non-retryable message distinct from the generic "AI service error. Please try again." used for retryable failures.
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual chat/AI screens, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip. The sandbox HAS an AI provider bonded, so the flow runs live end-to-end; AI output is NON-DETERMINISTIC, so assert on STRUCTURE/behavior, not exact text:
chat() yields text chunks then a final done; a single late
blob means the reply was awaited whole and streaming is broken.)messages history is sent, not just the last
line.