| name | ai-model-web |
| description | Use this skill when developing browser/Web applications (React/Vue/Angular, static websites, SPAs) that need AI capabilities. Features text generation (generateText) and streaming (streamText) via @cloudbase/js-sdk. Built-in models include Hunyuan (hunyuan-2.0-instruct-20251111 recommended) and DeepSeek (deepseek-v3.2 recommended). NOT for Node.js backend (use ai-model-nodejs), WeChat Mini Program (use ai-model-wechat), or image generation (Node SDK only). |
| alwaysApply | false |
When to use this skill
Use this skill for calling AI models in browser/Web applications using @cloudbase/js-sdk.
Use it when you need to:
- Integrate AI text generation in a frontend Web app
- Stream AI responses for better user experience
- Call Hunyuan or DeepSeek models from browser
Do NOT use for:
- Node.js backend or cloud functions → use
ai-model-nodejs skill
- WeChat Mini Program → use
ai-model-wechat skill
- Image generation → use
ai-model-nodejs skill (Node SDK only)
- HTTP API integration → use
http-api skill
Available Providers and Models
CloudBase provides these built-in providers and models:
| Provider | Models | Recommended |
|---|
hunyuan-exp | hunyuan-turbos-latest, hunyuan-t1-latest, hunyuan-2.0-thinking-20251109, hunyuan-2.0-instruct-20251111 | ✅ hunyuan-2.0-instruct-20251111 |
deepseek | deepseek-r1-0528, deepseek-v3-0324, deepseek-v3.2 | ✅ deepseek-v3.2 |
Installation
npm install @cloudbase/js-sdk
Initialization
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "<YOUR_ENV_ID>",
accessKey: "<YOUR_PUBLISHABLE_KEY>"
});
const auth = app.auth();
await auth.signInAnonymously();
const ai = app.ai();
Important notes:
- Always use synchronous initialization with top-level import
- User must be authenticated before using AI features
- Get
accessKey from CloudBase console
generateText() - Non-streaming
const model = ai.createModel("hunyuan-exp");
const result = await model.generateText({
model: "hunyuan-2.0-instruct-20251111",
messages: [{ role: "user", content: "你好,请你介绍一下李白" }],
});
console.log(result.text);
console.log(result.usage);
console.log(result.messages);
console.log(result.rawResponses);
streamText() - Streaming
const model = ai.createModel("hunyuan-exp");
const res = await model.streamText({
model: "hunyuan-2.0-instruct-20251111",
messages: [{ role: "user", content: "你好,请你介绍一下李白" }],
});
for await (let text of res.textStream) {
console.log(text);
}
for await (let data of res.dataStream) {
console.log(data);
}
const messages = await res.messages;
const usage = await res.usage;
Type Definitions
interface BaseChatModelInput {
model: string;
messages: Array<ChatModelMessage>;
temperature?: number;
topP?: number;
}
type ChatModelMessage =
| { role: "user"; content: string }
| { role: "system"; content: string }
| { role: "assistant"; content: string };
interface GenerateTextResult {
text: string;
messages: Array<ChatModelMessage>;
usage: Usage;
rawResponses: Array<unknown>;
error?: unknown;
}
interface {
: <>;
: <>;
: <[]>;
: <>;
?: ;
}
{
: ;
: ;
: ;
}
Best Practices
- Use streaming for long responses - Better user experience
- Handle errors gracefully - Wrap AI calls in try/catch
- Keep accessKey secure - Use publishable key, not secret key
- Initialize early - Initialize SDK in app entry point
- Ensure authentication - User must be signed in before AI calls