Wrapper around Baidu ERNIE large language models that use the Chat endpoint.

To use you should have the BAIDU_API_KEY and BAIDU_SECRET_KEY environment variable set.


const ernieTurbo = new ChatBaiduWenxin({
apiKey: "YOUR-API-KEY",
baiduSecretKey: "YOUR-SECRET-KEY",

const ernie = new ChatBaiduWenxin({
model: "ERNIE-Bot",
temperature: 1,
apiKey: "YOUR-API-KEY",
baiduSecretKey: "YOUR-SECRET-KEY",

const messages = [new HumanMessage("Hello")];

let res = await ernieTurbo.call(messages);

res = await ernie.call(messages);

Hierarchy (view full)


  • BaiduWenxinChatInput



accessToken: string
apiUrl: string
model: string = "ERNIE-Bot-turbo"
modelName: string = "ERNIE-Bot-turbo"
streaming: boolean = false
apiKey?: string
baiduApiKey?: string
baiduSecretKey?: string
penaltyScore?: number
prefixMessages?: WenxinMessage[]
temperature?: number
topP?: number
userId?: string



  • Method that retrieves the access token for making requests to the Baidu API.


    • Optional options: unknown

      Optional parsed call options.

    Returns Promise<any>

    The access token for making requests to the Baidu API.

  • Get the identifying parameters for the model

    Returns {
        model_name: string;
        penalty_score?: number;
        stream?: boolean;
        system?: string;
        temperature?: number;
        top_p?: number;
        user_id?: string;

    • model_name: string
    • Optional penalty_score?: number
    • Optional stream?: boolean
    • Optional system?: string
    • Optional temperature?: number
    • Optional top_p?: number
    • Optional user_id?: string

Generated using TypeDoc