Security note. Pasting a key here calls the provider directly from the browser, which exposes the key. That is fine for a quick local trial only. In production, leave apiKey empty and set the proxyUrl option (or a sendRequest callback) so your own backend holds the key and forwards the request to the provider.

jQuery Chat: Default Functionality

The jqxChat widget embeds an AI assistant chat and connects it to your platform key.

A live JavaScript/jQuery example of jqxChat, the jQWidgets Chat component, with its complete source code below. It is one of 5 jqxChat demos for jQuery.

jqxChat API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxbuttons.js, jqxscrollbar.js, jqxlistbox.js, jqxdropdownlist.js, jqxchat.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    var theme = 'light';

    // ---- the chat component ----
    $('#chat').jqxChat({
        theme: theme,
        width: 440,
        height: 600,
        title: 'AI Assistant',
        subtitle: 'Powered by Claude',
        colorScheme: 'auto',
        accentColor: '#6366f1',
        provider: 'anthropic',                 // "anthropic" (Claude) | "openai" | "custom"
        model: 'claude-opus-4-8',              // most capable Claude model
        system: 'You are a friendly assistant embedded in a jQWidgets demo. ' +
                'Keep answers concise and format code with Markdown fences.',
        maxTokens: 1024,
        stream: true,
        welcomeMessage: 'Hi! Connect a platform key above, then ask me anything.',
        starterPrompts: [
            'What is jQWidgets?',
            'Show me a code example',
            'Explain streaming responses'
        ]
    });

    // ---- connection controls ----
    $('#provider').jqxDropDownList({
        theme: theme, width: 150, height: 30, autoDropDownHeight: true,
        source: ['anthropic', 'openai'], selectedIndex: 0
    });
    $('#applyKey').jqxButton({ theme: theme, width: 90, height: 30 });

    $('#applyKey').on('click', function () {
        var provider = $('#provider').jqxDropDownList('getSelectedItem').value;
        var model = provider === 'openai' ? 'gpt-4o-mini' : 'claude-opus-4-8';
        $('#chat').jqxChat({
            provider: provider,
            model: model,
            subtitle: 'Powered by ' + (provider === 'openai' ? 'OpenAI' : 'Claude'),
            apiKey: $('#apiKey').val()
        });
        $('#status').text('Connected to ' + provider + ' (' + model + ').');
        $('#chat').jqxChat('focus');
    });

    // ---- react to the widget's events ----
    $('#chat').on('messageSent', function (e) { console.log('user:', e.args.content); });
    $('#chat').on('messageReceived', function (e) { console.log('assistant:', e.args.content); });
    $('#chat').on('error', function (e) { $('#status').text('Error: ' + e.args.message); });
});

body.html

<div id="panel">
    <div class="row">
        <label for="apiKey">Platform key:</label>
        <input id="apiKey" type="password" placeholder="sk-ant-... or sk-..." autocomplete="off">
        <div id="provider"></div>
        <input type="button" id="applyKey" value="Connect">
        <span id="status"></span>
    </div>
    <div id="note">
        <strong>Security note.</strong> Pasting a key here calls the provider directly from the browser, which
        exposes the key. That is fine for a quick local trial only. In production, leave <code>apiKey</code> empty
        and set the <code>proxyUrl</code> option (or a <code>sendRequest</code> callback) so your own backend
        holds the key and forwards the request to the provider.
    </div>
    <div class="links">
        No key handy? Try the offline demos:
        <a href="mock-assistant.htm">Offline assistant</a>
        <a href="floating-assistant.htm">Floating launcher</a>
        <a href="custom-branding.htm">Custom branding</a>
        <a href="events-and-methods.htm">Events &amp; methods</a>
        <a href="themes.htm">Dark mode &amp; accents</a>
    </div>
</div>

<div id="chat"></div>

More jQuery Chat demos