Ainative React Sdk
/install 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 (
\x3CAINativeProvider config={{ apiKey: 'ak_your_key' }}>
\x3CYourApp />
\x3C/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 (
\x3Cdiv>
{messages.map((msg, i) => (
\x3Cdiv key={i} className={`message ${msg.role}`}>
\x3Cstrong>{msg.role}:\x3C/strong> {msg.content}
\x3C/div>
))}
{isLoading && \x3Cdiv>Thinking...\x3C/div>}
{error && \x3Cdiv className="error">Error: {error.message}\x3C/div>}
\x3Cinput
onKeyDown={(e) => e.key === 'Enter' && handleSend(e.currentTarget.value)}
placeholder="Type a message..."
/>
\x3C/div>
);
}
useChat Options
| Option | Type | Default | Description |
|---|---|---|---|
model |
string | — | Model ID (e.g. claude-3-5-sonnet-20241022) |
temperature |
number | 0.7 | Randomness (0–1) |
max_tokens |
number | 1024 | Max response tokens |
useChat Return
| Field | Type | Description |
|---|---|---|
messages |
Message[] |
Full conversation history |
isLoading |
boolean |
True while request in flight |
error |
AINativeError | null |
Last error, if any |
sendMessage |
(msgs: Message[]) => Promise\x3C...> |
Send next message |
useCredits Hook
import { useCredits } from '@ainative/react-sdk';
function CreditsBar() {
const { balance, isLoading, error, refetch } = useCredits();
if (isLoading) return \x3Cdiv>Loading credits...\x3C/div>;
if (error) return \x3Cdiv>Error: {error.message}\x3C/div>;
return (
\x3Cdiv>
\x3Cspan>{balance?.remaining_credits} credits remaining\x3C/span>
\x3Cspan> | Plan: {balance?.plan}\x3C/span>
\x3Cbutton onClick={refetch}>Refresh\x3C/button>
\x3C/div>
);
}
useCredits Return
| Field | Type | Description |
|---|---|---|
balance |
CreditBalance | null |
Balance data |
isLoading |
boolean |
Fetching state |
error |
AINativeError | null |
Error state |
refetch |
() => void |
Manually 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
\x3CAINativeProvider config={{ apiKey: process.env.REACT_APP_AINATIVE_API_KEY! }}>
References
packages/sdks/react/src/hooks/useChat.ts— Hook implementationpackages/sdks/react/src/hooks/useCredits.ts— Credits hookpackages/sdks/react/src/AINativeProvider.tsx— Provider contextpackages/sdks/react/src/index.ts— Package exports
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install ainative-react-sdk - After installation, invoke the skill by name or use
/ainative-react-sdk - Provide required inputs per the skill's parameter spec and get structured output
What is 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 completion... It is an AI Agent Skill for Claude Code / OpenClaw, with 139 downloads so far.
How do I install Ainative React Sdk?
Run "/install ainative-react-sdk" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Ainative React Sdk free?
Yes, Ainative React Sdk is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Ainative React Sdk support?
Ainative React Sdk is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Ainative React Sdk?
It is built and maintained by Toby Morning (@urbantech); the current version is v1.0.0.