ainative-react-sdk

Use @ainative/react-sdk to add AI chat and credits to React apps. Use when (1) Installing @ainative/react-sdk, (2) Using the useChat hook for chat completions, (3) Displaying credit balance with useCredits, (4) Setting up AINativeProvider, (5) Handling loading/error states in chat UI. Published npm package v1.0.1.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "ainative-react-sdk" with this command: npx skills add urbantech/ainative-react-sdk

@ainative/react-sdk

React hooks and components for AINative — chat completions, credit tracking, and managed sessions.

Install

npm install @ainative/react-sdk

Setup: AINativeProvider

Wrap your app (or a subtree) with the provider:

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

function App() {
  return (
    <AINativeProvider config={{ apiKey: 'ak_your_key' }}>
      <YourApp />
    </AINativeProvider>
  );
}

useChat Hook

import { useChat } from '@ainative/react-sdk';
import type { Message } from '@ainative/react-sdk';

function ChatUI() {
  const { messages, isLoading, error, sendMessage } = useChat({
    model: 'claude-3-5-sonnet-20241022',
    temperature: 0.7,
    max_tokens: 1024,
  });

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

  return (
    <div>
      {messages.map((msg, i) => (
        <div key={i} className={`message ${msg.role}`}>
          <strong>{msg.role}:</strong> {msg.content}
        </div>
      ))}
      {isLoading && <div>Thinking...</div>}
      {error && <div className="error">Error: {error.message}</div>}
      <input
        onKeyDown={(e) => e.key === 'Enter' && handleSend(e.currentTarget.value)}
        placeholder="Type a message..."
      />
    </div>
  );
}

useChat Options

OptionTypeDefaultDescription
modelstringModel ID (e.g. claude-3-5-sonnet-20241022)
temperaturenumber0.7Randomness (0–1)
max_tokensnumber1024Max response tokens

useChat Return

FieldTypeDescription
messagesMessage[]Full conversation history
isLoadingbooleanTrue while request in flight
errorAINativeError | nullLast error, if any
sendMessage(msgs: Message[]) => Promise<...>Send next message

useCredits Hook

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

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

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

  return (
    <div>
      <span>{balance?.remaining_credits} credits remaining</span>
      <span> | Plan: {balance?.plan}</span>
      <button onClick={refetch}>Refresh</button>
    </div>
  );
}

useCredits Return

FieldTypeDescription
balanceCreditBalance | nullBalance data
isLoadingbooleanFetching state
errorAINativeError | nullError state
refetch() => voidManually refresh

CreditBalance shape: { remaining_credits: number, plan: string, ... }

Exports

import {
  AINativeProvider,
  useChat,
  useCredits,
  useAINativeContext,  // access raw config/baseUrl
  type Message,
  type ChatCompletionResponse,
  type CreditBalance,
  type AINativeError,
  type UseChatOptions,
} from '@ainative/react-sdk';

Environment Variable (CRA / Vite)

REACT_APP_AINATIVE_API_KEY=ak_your_key   # CRA
VITE_AINATIVE_API_KEY=ak_your_key        # Vite
<AINativeProvider config={{ apiKey: process.env.REACT_APP_AINATIVE_API_KEY! }}>

References

  • packages/sdks/react/src/hooks/useChat.ts — Hook implementation
  • packages/sdks/react/src/hooks/useCredits.ts — Credits hook
  • packages/sdks/react/src/AINativeProvider.tsx — Provider context
  • packages/sdks/react/src/index.ts — Package exports

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Amazon Push Score

Use when user needs Amazon push score calculation and optimization strategy. Use when generating A9 algorithm optimization plans for Amazon listings. Use whe...

Registry SourceRecently Updated
General

运维助手 v2

运维助手 v2.1 - 支持本地、远程、多服务器集群监控 (安全增强版,密码加密、命令白名单)

Registry SourceRecently Updated
General

三重人格

一个窗口,三种情绪。恋人/损友/死敌随时切换,记忆永不串味。

Registry SourceRecently Updated
00Profile unavailable
General

Sun Tzu Perspective

孙子(孙武)的战略思维视角——以「不战而屈人之兵」为核心的全胜智慧。 适用于:战略规划、竞争分析、决策优化、领导力提升、商业谈判。 触发词:「孙子视角」「孙子兵法」「战略思维」「竞争策略」「知彼知己」。

Registry SourceRecently Updated