npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ainative/svelte-sdk

v1.0.0

Published

Official Svelte SDK for AINative Studio API - Stores and actions for chat completions and credit management

Readme

@ainative/svelte-sdk

Official Svelte SDK for AINative Studio API - Reactive stores for chat completions and credit management.

npm version License: MIT

Features

  • 🎯 Svelte Stores - Reactive stores that integrate seamlessly with Svelte
  • 💬 Chat Completions - Stream AI responses with createChat()
  • 💰 Credit Management - Track balance with createCredits()
  • 📘 TypeScript - Full type safety with TypeScript definitions
  • 🔄 Reactive - Built on Svelte's reactivity system
  • 🪶 Lightweight - Minimal bundle size with tree-shaking support
  • Svelte 4 & 5 - Compatible with both Svelte versions

Installation

npm install @ainative/svelte-sdk

Quick Start

1. Configure SDK

// +layout.svelte or app initialization
<script lang="ts">
  import { setAINativeConfig } from '@ainative/svelte-sdk';
  import { onMount } from 'svelte';

  onMount(() => {
    setAINativeConfig({
      apiKey: 'your-api-key-here',
      baseUrl: 'https://api.ainative.studio' // optional
    });
  });
</script>

2. Use Chat Store

<script lang="ts">
  import { createChat, type Message } from '@ainative/svelte-sdk';

  const chat = createChat({
    model: 'claude-3-5-sonnet-20241022'
  });

  let input = '';

  async function handleSubmit() {
    if (!input.trim()) return;

    const userMessage: Message = {
      role: 'user',
      content: input
    };

    try {
      await chat.sendMessage([...$chat.messages, userMessage]);
      input = '';
    } catch (err) {
      console.error('Failed to send message:', err);
    }
  }
</script>

<div class="chat-container">
  <div class="messages">
    {#each $chat.messages as msg}
      <div class="message-{msg.role}">
        <strong>{msg.role}:</strong> {msg.content}
      </div>
    {/each}
  </div>

  {#if $chat.error}
    <div class="error">{$chat.error.message}</div>
  {/if}

  <form on:submit|preventDefault={handleSubmit}>
    <input
      bind:value={input}
      disabled={$chat.isLoading}
      placeholder="Type your message..."
    />
    <button type="submit" disabled={$chat.isLoading || !input.trim()}>
      {$chat.isLoading ? 'Sending...' : 'Send'}
    </button>
  </form>

  <button on:click={() => chat.reset()} type="button">
    Reset Chat
  </button>
</div>

3. Use Credits Store

<script lang="ts">
  import { createCredits } from '@ainative/svelte-sdk';

  const credits = createCredits({
    autoFetch: true
  });
</script>

<div class="credits-display">
  {#if $credits.isLoading}
    <div>Loading balance...</div>
  {:else if $credits.error}
    <div class="error">{$credits.error.message}</div>
  {:else if $credits.balance}
    <div>
      <p>Balance: {$credits.balance.balance} {$credits.balance.currency}</p>
      <p>User ID: {$credits.balance.userId}</p>
    </div>
  {/if}

  <button on:click={() => credits.refetch()} disabled={$credits.isLoading}>
    Refresh Balance
  </button>
</div>

Using Derived Stores

<script lang="ts">
  import { createChat } from '@ainative/svelte-sdk';

  const chat = createChat();

  // Access derived stores directly
  const { messages, isLoading, error } = chat;
</script>

{#each $messages as msg}
  <div>{msg.content}</div>
{/each}

{#if $isLoading}
  <div>Loading...</div>
{/if}

{#if $error}
  <div>Error: {$error.message}</div>
{/if}

API Reference

setAINativeConfig(config)

Configure the SDK with your API key and optional base URL.

import { setAINativeConfig } from '@ainative/svelte-sdk';

setAINativeConfig({
  apiKey: 'your-api-key',
  baseUrl: 'https://api.ainative.studio' // optional
});

createChat(options?)

Create a reactive chat store for managing conversations.

Options:

  • initialMessages?: Message[] - Initial conversation messages
  • model?: string - AI model to use (default: claude-3-5-sonnet-20241022)

Returns:

  • Store with messages, isLoading, error (derived stores)
  • sendMessage(messages: Message[]) - Send messages
  • reset() - Reset conversation

createCredits(options?)

Create a reactive credits store for monitoring balance.

Options:

  • autoFetch?: boolean - Automatically fetch on creation (default: false)

Returns:

  • Store with balance, isLoading, error (derived stores)
  • refetch() - Manually refetch balance

TypeScript Support

Full TypeScript definitions included:

import type {
  AINativeConfig,
  Message,
  ChatCompletionResponse,
  CreditBalance,
  AINativeError,
  ChatOptions,
  CreditsOptions
} from '@ainative/svelte-sdk';

SvelteKit Integration

// src/routes/+layout.ts
import { setAINativeConfig } from '@ainative/svelte-sdk';
import { PUBLIC_AINATIVE_API_KEY } from '$env/static/public';

export const load = () => {
  setAINativeConfig({
    apiKey: PUBLIC_AINATIVE_API_KEY
  });
};

Examples

See the /examples directory for complete example applications:

  • Basic chat application
  • Credit monitoring dashboard
  • Multi-model comparison
  • SvelteKit integration

License

MIT © AINative Studio

Support

  • Documentation: https://api.ainative.studio/docs
  • Email: [email protected]
  • Discord: https://discord.com/invite/paipalooza
  • Issues: https://github.com/AINative-Studio/ainative-sdks/issues