SDK Overview
Asgard publishes official JavaScript and React SDKs so you can integrate chatbot functionality without handling the underlying API details yourself.
What the SDK gives you
- Simplified API access: REST requests are wrapped, with authentication and endpoint configuration handled in one place
- SSE stream handling: Server-Sent Events are processed for you, so bot responses arrive as they are produced
- Channel management: session persistence is built in, supporting multi-turn conversations
- React components:
@asgard-js/reactships a ready-made chat UI along with hooks
Installation
JavaScript SDK
For any JavaScript environment (Node.js, the browser, framework-agnostic):
npm install @asgard-js/core
React SDK
For React applications, including UI components and hooks:
npm install @asgard-js/react
@asgard-js/reacttakes@asgard-js/coreas a peer dependency, so install both.
Quick start
This example uses the low-level @asgard-js/core API to send a message and receive a streamed response:
import { AsgardServiceClient, Channel, Conversation } from '@asgard-js/core';
const client = new AsgardServiceClient({
botProviderEndpoint:
'https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}',
});
const conversation = new Conversation({ messages: new Map() });
const channel = await Channel.reset({
client,
customChannelId: 'channel-123',
conversation,
statesObserver: (states) => {
console.log('Messages:', Array.from(states.conversation.messages.values()));
},
});
await channel.sendMessage({ text: 'Hello, tell me about yourself' });
In React, the <Chatbot> component is the recommended starting point:
import { Chatbot } from '@asgard-js/react';
import '@asgard-js/react/style';
export default function App() {
return (
<div style={{ height: '100vh' }}>
<Chatbot
title="My AI assistant"
customChannelId="user-123"
config={{
botProviderEndpoint:
'https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}',
}}
/>
</div>
);
}
SDK compared with calling the REST API directly
| Capability | SDK | REST API |
|---|---|---|
| SSE stream handling | Handled for you | Implement it yourself |
| Authentication | Configured once, applied automatically | Add the header on every request |
| Channel management | Session persistence built in | Maintain channelId yourself |
| React integration | Hooks and components provided | Wrap it yourself |
| Error handling | One error interface | Parse each kind of error yourself |
| TypeScript support | Full type definitions | Define the types yourself |
Further reading
- JavaScript SDK reference — the full
@asgard-js/coreAPI - React SDK reference —
@asgard-js/reactcomponents and hooks - SDK Demo — a runnable example of every SDK capability (message templates, theming, authentication, headless usage)
- SDK Demo — integration overview — the whole path from creating a bot to shipping a frontend
GitHub
Source and releases: asgard-ai-platform/asgard-js-sdk