Ainative Svelte Sdk
/install ainative-svelte-sdk
@ainative/svelte-sdk
Svelte stores and utilities for AINative chat completions.
Install
npm install @ainative/svelte-sdk
Configure
// src/lib/ainative.ts
import { setAINativeConfig } from '@ainative/svelte-sdk';
setAINativeConfig({
apiKey: import.meta.env.VITE_AINATIVE_API_KEY,
baseUrl: 'https://api.ainative.studio',
});
Call this once in your app root (+layout.svelte or App.svelte).
createChatStore
\x3C!-- src/lib/Chat.svelte -->
\x3Cscript lang="ts">
import { createChatStore } from '@ainative/svelte-sdk';
const chat = createChatStore({
model: 'claude-3-5-sonnet-20241022',
});
let input = '';
async function send() {
if (!input.trim()) return;
const userMsg = { role: 'user' as const, content: input };
input = '';
await chat.sendMessage([...$chat.messages, userMsg]);
}
\x3C/script>
{#each $chat.messages as msg}
\x3Cdiv class="message {msg.role}">
\x3Cstrong>{msg.role}:\x3C/strong> {msg.content}
\x3C/div>
{/each}
{#if $chat.isLoading}
\x3Cp>Thinking...\x3C/p>
{/if}
{#if $chat.error}
\x3Cp class="error">Error: {$chat.error.message}\x3C/p>
{/if}
\x3Cinput bind:value={input} on:keydown={(e) => e.key === 'Enter' && send()} />
\x3Cbutton on:click={send} disabled={$chat.isLoading}>Send\x3C/button>
Store Shape
$chat is a reactive store with this shape:
| Field | Type | Description |
|---|---|---|
messages |
Message[] |
Full conversation history |
isLoading |
boolean |
True while request in flight |
error |
AINativeError | null |
Last error |
createChatStore Options
| Option | Type | Default | Description |
|---|---|---|---|
model |
string | — | Model ID |
initialMessages |
Message[] |
[] |
Seed conversation |
SvelteKit — Server Route
For server-side calls, use the raw API directly (no browser auth exposure):
// src/routes/api/chat/+server.ts
import { AINATIVE_API_KEY } from '$env/static/private';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ request }) => {
const { messages } = await request.json();
const resp = await fetch('https://api.ainative.studio/v1/public/chat/completions', {
method: 'POST',
headers: {
'X-API-Key': AINATIVE_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'claude-3-5-sonnet-20241022',
messages,
}),
});
return new Response(resp.body, {
headers: { 'Content-Type': 'application/json' },
});
};
Environment Variables
# .env
VITE_AINATIVE_API_KEY=ak_your_key # Client-safe (public key only)
AINATIVE_API_KEY=ak_your_key # Server-side (SvelteKit $env/static/private)
Use server routes for production — never expose API keys in client bundles.
Exports
import {
createChatStore,
setAINativeConfig,
ainativeConfig,
type Message,
type ChatState,
type AINativeError,
} from '@ainative/svelte-sdk';
References
packages/sdks/svelte/src/stores/chat.ts— Chat store implementationpackages/sdks/svelte/src/stores/config.ts— Config storepackages/sdks/svelte/src/index.ts— Package exports
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install ainative-svelte-sdk - After installation, invoke the skill by name or use
/ainative-svelte-sdk - Provide required inputs per the skill's parameter spec and get structured output
What is Ainative Svelte Sdk?
Use @ainative/svelte-sdk to add AI chat to Svelte/SvelteKit apps. Use when (1) Installing @ainative/svelte-sdk, (2) Using Svelte stores for chat state, (3) C... It is an AI Agent Skill for Claude Code / OpenClaw, with 118 downloads so far.
How do I install Ainative Svelte Sdk?
Run "/install ainative-svelte-sdk" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Ainative Svelte Sdk free?
Yes, Ainative Svelte Sdk is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Ainative Svelte Sdk support?
Ainative Svelte Sdk is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Ainative Svelte Sdk?
It is built and maintained by Toby Morning (@urbantech); the current version is v1.0.0.