You can use the chat completion endpoint with Vercel AI SDK under two lines of code change.

Example

Add Keywords AI parameters

Adding Keywords AI parameters to the Vercel AI SDK is different than other frameworks. Here is an example of how to do it:

1

Specify Keywords AI params in an object

You should create an object with the Keywords AI parameters you want to use. Add parameters you want to use as keys in the object.

const keywordsAIHeaderContent = {
    "customer_params": {
        "customer_identifier": "customer_123",
        "name": "Hendrix Liu", //optional
        "email": "hendrix@keywordsai.co" //optional
    }
    // "cache_enabled": true or other parameters
}
2

Encode the object as a string

You should encode the object as a string and then you can send it as a header in your request.

const encoded = Buffer.from(JSON.stringify(keywordsAIHeaderContent)).toString('base64');
3

Add the header to your request

You should send it in the X-Data-Keywordsai-Params header.

4

Full example