
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
ai-react-hooks
Advanced tools
A powerful collection of React hooks for AI models including ChatGPT, Ollama, Groq, DeepSeek, Anthropic, Google Gemini, and more.
Unified API: Single hook (useAI) for all providers
Multi-Provider: OpenAI, Anthropic, Google Gemini, Ollama, Groq, DeepSeek
Feature-Rich: Chat, image generation, speech-to-text, summarization
TypeScript: Full type safety and IntelliSense support
Lightweight: Zero dependencies, tree-shakeable
React 18+: Built for modern React applications
npm install ai-react-hooks
yarn add ai-react-hooks
pnpm add ai-react-hooks
🚀 Quick Start
import { useAI } from "ai-react-hooks";
function ChatComponent() {
const { ask, response, loading, error } = useAI({
provider: "openai", // "ollama", "groq", "deepseek", etc.
apiKey: process.env.OPENAI_API_KEY,
model: "gpt-4o-mini",
});
const handleClick = () => {
ask("Explain quantum computing in simple terms");
};
return (
<div>
<button onClick={handleClick} disabled={loading}>
{loading ? "Thinking..." : "Ask AI"}
</button>
{response && <p>{response}</p>}
{error && <p className="error">Error: {error.message}</p>}
</div>
);
}
| Hook | Provider | Description |
|---|---|---|
| useAI | All Providers | Unified hook for any AI provider |
| useChatGPT | OpenAI | GPT-4, GPT-4o, GPT-3.5 |
| useAnthropic | Anthropic | Claude 3, Claude Instant |
| useGoogleGemini | Gemini Pro, Gemini Flash | |
| useOllama | Ollama | Local models (Llama, Mistral) |
| useGroq | Groq | Ultra-fast LLM inference |
| useDeepSeek | DeepSeek | DeepSeek models |
| useSummarize | Text Processing | Text summarization |
| useAiImageGenerator | Image Generation | DALL·E, Stable Diffusion |
| useSpeechToText | Browser API | Web Speech API integration |
import { useChatGPT } from "ai-react-hooks";
function OpenAIChat() {
const { ask, response, loading } = useChatGPT({
apiKey: "your-openai-key",
model: "gpt-4",
temperature: 0.7,
});
return (
<div>
<button onClick={() => ask("Write a poem about React hooks")}>
Generate Poem
</button>
{loading && <span>Thinking...</span>}
{response && <p>{response}</p>}
</div>
);
}
import { useAiImageGenerator } from "ai-react-hooks";
function ImageGenerator() {
const { generate, imageUrl, loading } = useAiImageGenerator({
provider: "openai",
apiKey: process.env.OPENAI_API_KEY,
size: "1024x1024",
});
return (
<div>
<input
placeholder="Describe an image..."
onKeyPress={(e) => e.key === 'Enter' && generate(e.target.value)}
/>
{loading && <p>Generating...</p>}
{imageUrl && <img src={imageUrl} alt="Generated" />}
</div>
)
import { useSpeechToText } from "ai-react-hooks";
function VoiceInput() {
const { start, stop, text, listening } = useSpeechToText({
continuous: true,
language: "en-US",
});
return (
<div>
<button onClick={listening ? stop : start}>
{listening ? "Stop Recording" : "Start Recording"}
</button>
<p>{text || "Speak to see transcription..."}</p>
</div>
);
}
Environment Setup
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_AI_API_KEY=AIza...
// OpenAI
const openAI = useChatGPT({
apiKey: "your-key",
model: "gpt-4",
temperature: 0.7,
maxTokens: 1000,
});
// Anthropic
const anthropic = useAnthropic({
apiKey: "your-key",
model: "claude-3-opus-20240229",
maxTokens: 1000,
});
// Ollama (Local)
const ollama = useOllama({
baseUrl: "http://localhost:11434",
model: "llama2",
});
| Prop | Type | Description |
|---|---|---|
| apiKey | string | Provider API key |
| model | string | Model identifier |
| temperature | number | Creativity level (0–1) |
| maxTokens | number | Maximum response length |
All hooks return an object with:
| Property | Type | Description |
|---|---|---|
| ask / generate | Function | Trigger AI request |
| response | string | null | AI response |
| loading | boolean | Request in progress |
| error | Error | null | Error information |
| reset | Function | Reset hook state |
Contributions are welcome! Please read the Contributing Guide for details.
Steps to contribute:
Fork the repository
Create a feature branch
Commit your changes
Push to your branch
Open a Pull Request
Start Ollama with CORS enabled:
ollama serve --cors "*"
API Key Security
Always use environment variables for API keys:
import { useChatGPT } from 'your-package-name';
const { ask } = useChatGPT({
apiKey: process.env.OPENAI_API_KEY, // ✅ Secure
// apiKey: "sk-..." // ❌ Do not hardcode
});
MIT © Yared Abebe
FAQs
A powerful collection of React hooks for AI models including ChatGPT, Ollama, Groq, DeepSeek, Anthropic, Google Gemini, and more.
The npm package ai-react-hooks receives a total of 1 weekly downloads. As such, ai-react-hooks popularity was classified as not popular.
We found that ai-react-hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.