Third-Party Models
This guide explains how to call third-party models configured in the CloudBase console (such as DeepSeek, Zhipu, self-hosted OpenAI-compatible services, third-party image generation services, and more).
Prerequisites
- Go to the CloudBase AI Console → select Third-Party Models.
- Click Add Model Provider and fill in the Provider Identifier, BaseURL, API Key, and other required fields.
- After saving, use the Provider Identifier from the console as the argument when calling the SDK.
For the full setup steps for custom models, see Connect to Models.
Text Models
When calling createModel(), replace the argument with the Provider Identifier from the console. The example below uses my-deepseek:
// 'my-deepseek' is the Provider Identifier configured in the console
const model = ai.createModel("my-deepseek");
const res = await model.generateText({
model: "deepseek-chat", // The actual model name
messages: [
{ role: "user", content: "Tell me about Li Bai" },
],
});
console.log(res.text);
For streaming, use streamText():
const model = ai.createModel("my-deepseek");
const res = await model.streamText({
model: "deepseek-chat",
messages: [{ role: "user", content: "Write a seven-character quatrain" }],
});
for await (const chunk of res.textStream) {
console.log(chunk);
}
For more usage details, see Node SDK.
Image Models
When calling createImageModel(), replace the argument with the Provider Identifier from the console. The example below uses my-image-provider:
const imageModel = ai.createImageModel("my-image-provider");
const res = await imageModel.generateImage({
model: "your-model-name", // The actual model name
prompt: "A cute cat playing on the grass",
});
console.log(res.data[0].url);
Custom API Sub-Path
By default, the SDK uses the OpenAI-compatible image generation path images/generations. If the third-party service uses a different path, you can override it explicitly via generateImageSubUrlConfig:
const imageModel = ai.createImageModel("my-image-provider");
// First-level key is the Provider Identifier; second-level key is the Model Name
imageModel.generateImageSubUrlConfig["my-image-provider"]["custom-model"] = "images/custom/generations";
const res = await imageModel.generateImage({
model: "custom-model",
prompt: "A cute cat playing on the grass",
});
The final request URL becomes:
https://<ENV_ID>.api.tcloudbasegateway.com/v1/ai/<provider-identifier>/<sub-path>
For more image generation capabilities, see Node SDK.