{"_id":"@ainative/react-sdk","_rev":"2-099be9f8f7ce8f2fca5997c6cb2dacd3","name":"@ainative/react-sdk","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@ainative/react-sdk","version":"1.0.0","keywords":["ainative","react","hooks","api","sdk","chat","ai","typescript"],"author":{"name":"AINative Studio"},"license":"MIT","_id":"@ainative/react-sdk@1.0.0","maintainers":[{"name":"ainative-studio","email":"toby@rely.ventures"}],"homepage":"https://ainative.studio","bugs":{"url":"https://github.com/AINative-Studio/core/issues"},"dist":{"shasum":"8fbfbd8d2272da838daa8a969f2ae55b633fa731","tarball":"https://registry.npmjs.org/@ainative/react-sdk/-/react-sdk-1.0.0.tgz","fileCount":19,"integrity":"sha512-zLMp4TTVaHsCoAKYBTRLILHa1cEngRQXKET1FMvedEGM6CzlXaRQ9sDRQbiTS/GTO+IOgQcoo7IaIdcRPzigvw==","signatures":[{"sig":"MEUCIQCTgWZqJBJpLhsv+2DVc1c54Ld2ICQc3tCXQgPzgXxhHQIgAkn0tX99kUs79E2gcQ0LqlDbp5iQHLYX335rxRu9CL0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":50640},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.esm.js","engines":{"node":">=14.0.0"},"gitHead":"8a82dd95afbd1c89bee4517527380f9359448e24","scripts":{"lint":"eslint . --ext .ts,.tsx","test":"jest","build":"rollup -c rollup.config.mjs","lint:fix":"eslint . --ext .ts,.tsx --fix","test:watch":"jest --watch","type-check":"tsc --noEmit","build:watch":"rollup -c -w","test:coverage":"jest --coverage","prepublishOnly":"npm run test && npm run build"},"_npmUser":{"name":"ainative-studio","email":"toby@rely.ventures"},"repository":{"url":"git+https://github.com/AINative-Studio/core.git","type":"git","directory":"packages/sdks/react"},"_npmVersion":"10.9.4","description":"Official React SDK for AINative Studio API - Simple hooks for chat completions and credit management","directories":{},"_nodeVersion":"22.21.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","react":"^18.2.0","tslib":"^2.6.2","eslint":"^8.54.0","rollup":"^3.29.4","ts-jest":"^29.1.1","react-dom":"^18.2.0","typescript":"^5.3.2","@types/jest":"^29.5.10","@types/react":"^18.2.45","rollup-plugin-dts":"^5.3.1","eslint-plugin-react":"^7.33.2","@rollup/plugin-terser":"^0.4.4","@testing-library/react":"^14.1.2","jest-environment-jsdom":"^29.7.0","@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-typescript":"^11.1.5","@typescript-eslint/parser":"^6.13.0","eslint-plugin-react-hooks":"^4.6.0","@rollup/plugin-node-resolve":"^15.2.3","@typescript-eslint/eslint-plugin":"^6.13.0"},"peerDependencies":{"react":"^18.0.0"},"_npmOperationalInternal":{"tmp":"tmp/react-sdk_1.0.0_1768462962784_0.6345477721409241","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@ainative/react-sdk","version":"1.0.1","description":"Official React SDK for AINative Studio API - Simple hooks for chat completions and credit management","main":"dist/index.js","module":"dist/index.esm.js","types":"dist/index.d.ts","scripts":{"build":"rollup -c rollup.config.mjs","build:watch":"rollup -c -w","test":"jest","test:watch":"jest --watch","test:coverage":"jest --coverage","lint":"eslint . --ext .ts,.tsx","lint:fix":"eslint . --ext .ts,.tsx --fix","type-check":"tsc --noEmit","prepublishOnly":"npm run test && npm run build"},"keywords":["ainative","react","hooks","api","sdk","chat","ai","typescript"],"author":{"name":"AINative Studio"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/AINative-Studio/ainative-sdks.git"},"bugs":{"url":"https://github.com/AINative-Studio/ainative-sdks/issues"},"homepage":"https://ainative.studio","peerDependencies":{"react":"^18.0.0"},"dependencies":{},"devDependencies":{"@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-node-resolve":"^15.2.3","@rollup/plugin-typescript":"^11.1.5","@rollup/plugin-terser":"^0.4.4","@testing-library/react":"^14.1.2","@types/jest":"^29.5.10","@types/react":"^18.2.45","@typescript-eslint/eslint-plugin":"^6.13.0","@typescript-eslint/parser":"^6.13.0","eslint":"^8.54.0","eslint-plugin-react":"^7.33.2","eslint-plugin-react-hooks":"^4.6.0","jest":"^29.7.0","jest-environment-jsdom":"^29.7.0","react":"^18.2.0","react-dom":"^18.2.0","rollup":"^3.29.4","rollup-plugin-dts":"^5.3.1","ts-jest":"^29.1.1","tslib":"^2.6.2","typescript":"^5.3.2"},"engines":{"node":">=14.0.0"},"_id":"@ainative/react-sdk@1.0.1","gitHead":"8a82dd95afbd1c89bee4517527380f9359448e24","_nodeVersion":"22.21.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-iBOjA/O6XrMzmJVV9fP/2fv2CzofTPNQW+R+RbNL3RaPE8qet4iuLtrAhGoDr1b22/FoHhcdVSrSnGMQJ7YiEQ==","shasum":"02a16cd96998b614f01709141339a80235604c27","tarball":"https://registry.npmjs.org/@ainative/react-sdk/-/react-sdk-1.0.1.tgz","fileCount":19,"unpackedSize":50618,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCTkeW6wz84SIpW9+rzTpu4cSDOPhVIQwkvuLS40tncPAIhANhzmILsJgnAFN++NL5J1UaRQKAuP24+GBi1vQdqBDVD"}]},"_npmUser":{"name":"ainative-studio","email":"toby@rely.ventures"},"directories":{},"maintainers":[{"name":"ainative-studio","email":"toby@rely.ventures"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-sdk_1.0.1_1768463453623_0.625616640882185"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-15T07:42:42.711Z","modified":"2026-01-15T07:50:53.903Z","1.0.0":"2026-01-15T07:42:42.918Z","1.0.1":"2026-01-15T07:50:53.755Z"},"bugs":{"url":"https://github.com/AINative-Studio/ainative-sdks/issues"},"author":{"name":"AINative Studio"},"license":"MIT","homepage":"https://ainative.studio","keywords":["ainative","react","hooks","api","sdk","chat","ai","typescript"],"repository":{"type":"git","url":"git+https://github.com/AINative-Studio/ainative-sdks.git"},"description":"Official React SDK for AINative Studio API - Simple hooks for chat completions and credit management","maintainers":[{"name":"ainative-studio","email":"toby@rely.ventures"}],"readme":"# @ainative/react-sdk\n\nOfficial React SDK for AINative Studio API. Simple hooks for chat completions and credit management with TypeScript support.\n\n## Installation\n\n```bash\nnpm install @ainative/react-sdk\n# or\nyarn add @ainative/react-sdk\n```\n\n## Quick Start\n\n```tsx\nimport { AINativeProvider, useChat, useCredits } from '@ainative/react-sdk';\n\nfunction App() {\n  return (\n    <AINativeProvider config={{ apiKey: 'your-jwt-token' }}>\n      <ChatComponent />\n      <CreditsDisplay />\n    </AINativeProvider>\n  );\n}\n\nfunction ChatComponent() {\n  const { messages, isLoading, error, sendMessage } = useChat({\n    model: 'llama-3.3-70b-instruct',\n    temperature: 0.7,\n  });\n\n  const handleSubmit = async (input: string) => {\n    await sendMessage([\n      ...messages,\n      { role: 'user', content: input }\n    ]);\n  };\n\n  return (\n    <div>\n      {messages.map((msg, i) => (\n        <div key={i}>\n          <strong>{msg.role}:</strong> {msg.content}\n        </div>\n      ))}\n      {isLoading && <p>Loading...</p>}\n      {error && <p>Error: {error.message}</p>}\n    </div>\n  );\n}\n\nfunction CreditsDisplay() {\n  const { balance, isLoading, error, refetch } = useCredits();\n\n  if (isLoading) return <p>Loading credits...</p>;\n  if (error) return <p>Error: {error.message}</p>;\n\n  return (\n    <div>\n      <h3>Credits: {balance?.remaining_credits}</h3>\n      <p>Plan: {balance?.plan}</p>\n      <button onClick={refetch}>Refresh</button>\n    </div>\n  );\n}\n```\n\n## API Reference\n\n### `<AINativeProvider>`\n\nProvides API configuration to child components.\n\n**Props:**\n\n- `config` - Configuration object\n  - `apiKey` (required) - Your JWT token from AINative authentication\n  - `baseUrl` (optional) - API base URL (defaults to `https://api.ainative.studio/api/v1`)\n\n**Example:**\n\n```tsx\n<AINativeProvider config={{\n  apiKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',\n  baseUrl: 'https://api.ainative.studio/api/v1'\n}}>\n  <YourApp />\n</AINativeProvider>\n```\n\n### `useAINative()`\n\nReturns the configured API client.\n\n**Returns:**\n\n```typescript\n{\n  config: AINativeConfig;\n  baseUrl: string;\n}\n```\n\n**Example:**\n\n```tsx\nfunction MyComponent() {\n  const client = useAINative();\n  console.log(client.baseUrl); // 'https://api.ainative.studio/api/v1'\n}\n```\n\n### `useChat(options?)`\n\nManages chat completion state and provides methods to send messages.\n\n**Options:**\n\n- `model` (optional) - Preferred model name (e.g., `'llama-3.3-70b-instruct'`)\n- `temperature` (optional) - Sampling temperature (0-2)\n- `max_tokens` (optional) - Maximum tokens in response\n- `onError` (optional) - Error callback\n- `onSuccess` (optional) - Success callback\n\n**Returns:**\n\n```typescript\n{\n  messages: Message[];\n  isLoading: boolean;\n  error: AINativeError | null;\n  response: ChatCompletionResponse | null;\n  sendMessage: (messages: Message[]) => Promise<ChatCompletionResponse | null>;\n  reset: () => void;\n}\n```\n\n**Example:**\n\n```tsx\nfunction Chat() {\n  const { messages, isLoading, sendMessage, reset } = useChat({\n    model: 'llama-3.3-70b-instruct',\n    temperature: 0.7,\n    max_tokens: 1000,\n    onSuccess: (response) => {\n      console.log('Credits consumed:', response.credits_consumed);\n    },\n    onError: (error) => {\n      if (error.status === 402) {\n        alert('Insufficient credits!');\n      }\n    },\n  });\n\n  const handleSend = async (userInput: string) => {\n    await sendMessage([\n      ...messages,\n      { role: 'user', content: userInput }\n    ]);\n  };\n\n  return (\n    <div>\n      {messages.map((msg, i) => (\n        <div key={i}>{msg.role}: {msg.content}</div>\n      ))}\n      {isLoading && <div>Thinking...</div>}\n      <button onClick={reset}>Clear Chat</button>\n    </div>\n  );\n}\n```\n\n### `useCredits()`\n\nFetches and manages user credit balance.\n\n**Returns:**\n\n```typescript\n{\n  balance: CreditBalance | null;\n  isLoading: boolean;\n  error: AINativeError | null;\n  refetch: () => Promise<void>;\n}\n```\n\n**Example:**\n\n```tsx\nfunction Credits() {\n  const { balance, isLoading, error, refetch } = useCredits();\n\n  if (isLoading) return <div>Loading...</div>;\n  if (error) return <div>Error: {error.message}</div>;\n\n  return (\n    <div>\n      <h2>Credits</h2>\n      <p>Total: {balance?.total_credits}</p>\n      <p>Used: {balance?.used_credits}</p>\n      <p>Remaining: {balance?.remaining_credits}</p>\n      <p>Plan: {balance?.plan}</p>\n      <p>Usage: {balance?.usage_percentage}%</p>\n      <button onClick={refetch}>Refresh</button>\n    </div>\n  );\n}\n```\n\n## TypeScript Types\n\nThe SDK exports all TypeScript types for your convenience:\n\n```typescript\nimport type {\n  AINativeConfig,\n  Message,\n  ChatCompletionRequest,\n  ChatCompletionResponse,\n  Usage,\n  CreditBalance,\n  AINativeError,\n  ChatState,\n  UseChatOptions,\n  UseCreditsReturn,\n} from '@ainative/react-sdk';\n```\n\n## Available Models\n\nModel access depends on your subscription plan:\n\n- **Free**: `llama-3.3-8b-instruct`\n- **Basic**: `llama-3.3-8b-instruct`, `llama-3.3-70b-instruct`\n- **Professional**: LLAMA models + `claude-sonnet-4.5`\n- **Enterprise**: All models including `claude-opus-4`\n\n## Error Handling\n\nThe SDK provides structured error handling:\n\n```tsx\nconst { error } = useChat({\n  onError: (error) => {\n    switch (error.status) {\n      case 402:\n        console.error('Insufficient credits:', error.message);\n        break;\n      case 403:\n        console.error('Model not available:', error.message);\n        break;\n      case 429:\n        console.error('Rate limit exceeded:', error.message);\n        break;\n      default:\n        console.error('API error:', error.message);\n    }\n  },\n});\n```\n\n## Credit Costs\n\n- **LLAMA 3.3-8B**: 0.1 base + 0.01 per 1K tokens\n- **LLAMA 3.3-70B**: 0.5 base + 0.05 per 1K tokens\n- **LLAMA 4 Maverick**: 1.0 base + 0.1 per 1K tokens\n- **Claude Sonnet 4.5**: 2.0 base + 0.2 per 1K tokens\n- **Claude Opus 4**: 5.0 base + 0.5 per 1K tokens\n\n## Authentication\n\nThis SDK requires a JWT token from AINative authentication. You handle authentication separately and pass the token to the provider:\n\n```tsx\n// Your authentication logic\nconst token = await authenticateUser(email, password);\n\n// Pass token to SDK\n<AINativeProvider config={{ apiKey: token }}>\n  <App />\n</AINativeProvider>\n```\n\n## Requirements\n\n- React 18.0.0 or higher\n- Node.js 14.0.0 or higher\n\n## Contributing\n\nSee the [main repository](https://github.com/AINative-Studio/core) for contribution guidelines.\n\n## License\n\nMIT\n\n## Support\n\n- Documentation: https://ainative.studio/docs\n- API Reference: https://api.ainative.studio/docs-enhanced\n- Issues: https://github.com/AINative-Studio/core/issues\n- Email: support@ainative.studio\n","readmeFilename":"README.md"}