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/react-sdk

v1.0.1

Published

Official React SDK for AINative Studio API - Simple hooks for chat completions and credit management

Readme

@ainative/react-sdk

Official React SDK for AINative Studio API. Simple hooks for chat completions and credit management with TypeScript support.

Installation

npm install @ainative/react-sdk
# or
yarn add @ainative/react-sdk

Quick Start

import { AINativeProvider, useChat, useCredits } from '@ainative/react-sdk';

function App() {
  return (
    <AINativeProvider config={{ apiKey: 'your-jwt-token' }}>
      <ChatComponent />
      <CreditsDisplay />
    </AINativeProvider>
  );
}

function ChatComponent() {
  const { messages, isLoading, error, sendMessage } = useChat({
    model: 'llama-3.3-70b-instruct',
    temperature: 0.7,
  });

  const handleSubmit = async (input: string) => {
    await sendMessage([
      ...messages,
      { role: 'user', content: input }
    ]);
  };

  return (
    <div>
      {messages.map((msg, i) => (
        <div key={i}>
          <strong>{msg.role}:</strong> {msg.content}
        </div>
      ))}
      {isLoading && <p>Loading...</p>}
      {error && <p>Error: {error.message}</p>}
    </div>
  );
}

function CreditsDisplay() {
  const { balance, isLoading, error, refetch } = useCredits();

  if (isLoading) return <p>Loading credits...</p>;
  if (error) return <p>Error: {error.message}</p>;

  return (
    <div>
      <h3>Credits: {balance?.remaining_credits}</h3>
      <p>Plan: {balance?.plan}</p>
      <button onClick={refetch}>Refresh</button>
    </div>
  );
}

API Reference

<AINativeProvider>

Provides API configuration to child components.

Props:

  • config - Configuration object
    • apiKey (required) - Your JWT token from AINative authentication
    • baseUrl (optional) - API base URL (defaults to https://api.ainative.studio/api/v1)

Example:

<AINativeProvider config={{
  apiKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
  baseUrl: 'https://api.ainative.studio/api/v1'
}}>
  <YourApp />
</AINativeProvider>

useAINative()

Returns the configured API client.

Returns:

{
  config: AINativeConfig;
  baseUrl: string;
}

Example:

function MyComponent() {
  const client = useAINative();
  console.log(client.baseUrl); // 'https://api.ainative.studio/api/v1'
}

useChat(options?)

Manages chat completion state and provides methods to send messages.

Options:

  • model (optional) - Preferred model name (e.g., 'llama-3.3-70b-instruct')
  • temperature (optional) - Sampling temperature (0-2)
  • max_tokens (optional) - Maximum tokens in response
  • onError (optional) - Error callback
  • onSuccess (optional) - Success callback

Returns:

{
  messages: Message[];
  isLoading: boolean;
  error: AINativeError | null;
  response: ChatCompletionResponse | null;
  sendMessage: (messages: Message[]) => Promise<ChatCompletionResponse | null>;
  reset: () => void;
}

Example:

function Chat() {
  const { messages, isLoading, sendMessage, reset } = useChat({
    model: 'llama-3.3-70b-instruct',
    temperature: 0.7,
    max_tokens: 1000,
    onSuccess: (response) => {
      console.log('Credits consumed:', response.credits_consumed);
    },
    onError: (error) => {
      if (error.status === 402) {
        alert('Insufficient credits!');
      }
    },
  });

  const handleSend = async (userInput: string) => {
    await sendMessage([
      ...messages,
      { role: 'user', content: userInput }
    ]);
  };

  return (
    <div>
      {messages.map((msg, i) => (
        <div key={i}>{msg.role}: {msg.content}</div>
      ))}
      {isLoading && <div>Thinking...</div>}
      <button onClick={reset}>Clear Chat</button>
    </div>
  );
}

useCredits()

Fetches and manages user credit balance.

Returns:

{
  balance: CreditBalance | null;
  isLoading: boolean;
  error: AINativeError | null;
  refetch: () => Promise<void>;
}

Example:

function Credits() {
  const { balance, isLoading, error, refetch } = useCredits();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <div>
      <h2>Credits</h2>
      <p>Total: {balance?.total_credits}</p>
      <p>Used: {balance?.used_credits}</p>
      <p>Remaining: {balance?.remaining_credits}</p>
      <p>Plan: {balance?.plan}</p>
      <p>Usage: {balance?.usage_percentage}%</p>
      <button onClick={refetch}>Refresh</button>
    </div>
  );
}

TypeScript Types

The SDK exports all TypeScript types for your convenience:

import type {
  AINativeConfig,
  Message,
  ChatCompletionRequest,
  ChatCompletionResponse,
  Usage,
  CreditBalance,
  AINativeError,
  ChatState,
  UseChatOptions,
  UseCreditsReturn,
} from '@ainative/react-sdk';

Available Models

Model access depends on your subscription plan:

  • Free: llama-3.3-8b-instruct
  • Basic: llama-3.3-8b-instruct, llama-3.3-70b-instruct
  • Professional: LLAMA models + claude-sonnet-4.5
  • Enterprise: All models including claude-opus-4

Error Handling

The SDK provides structured error handling:

const { error } = useChat({
  onError: (error) => {
    switch (error.status) {
      case 402:
        console.error('Insufficient credits:', error.message);
        break;
      case 403:
        console.error('Model not available:', error.message);
        break;
      case 429:
        console.error('Rate limit exceeded:', error.message);
        break;
      default:
        console.error('API error:', error.message);
    }
  },
});

Credit Costs

  • LLAMA 3.3-8B: 0.1 base + 0.01 per 1K tokens
  • LLAMA 3.3-70B: 0.5 base + 0.05 per 1K tokens
  • LLAMA 4 Maverick: 1.0 base + 0.1 per 1K tokens
  • Claude Sonnet 4.5: 2.0 base + 0.2 per 1K tokens
  • Claude Opus 4: 5.0 base + 0.5 per 1K tokens

Authentication

This SDK requires a JWT token from AINative authentication. You handle authentication separately and pass the token to the provider:

// Your authentication logic
const token = await authenticateUser(email, password);

// Pass token to SDK
<AINativeProvider config={{ apiKey: token }}>
  <App />
</AINativeProvider>

Requirements

  • React 18.0.0 or higher
  • Node.js 14.0.0 or higher

Contributing

See the main repository for contribution guidelines.

License

MIT

Support

  • Documentation: https://ainative.studio/docs
  • API Reference: https://api.ainative.studio/docs-enhanced
  • Issues: https://github.com/AINative-Studio/core/issues
  • Email: [email protected]