nostr-ai-provider
v0.1.2
Published
OpenAI-compatible provider with Nostr NIP-98 auth for Vercel's AI SDK
Readme
Nostr (NIP-98) AI Provider for Vercel's AI SDK
An OpenAI-compatible provider for Vercel's AI SDK that uses Nostr NIP-98 authentication instead of traditional API keys. This allows you to authenticate AI API requests using Nostr keypairs.
Features
- NIP-98 Authentication: Authenticate requests using Nostr signatures instead of API keys
- OpenAI-Compatible: Expects the provider to be OpenAI-compatible (except with NIP-98 auth)
- Flexible Authentication: Use either an nsec or a custom NIP-07-compatible signer object
- Vercel AI SDK Integration: Drop-in replacement for standard OpenAI provider
Installation
npm i nostr-ai-providerUsage
import { createNostrAIProvider } from "nostr-ai-provider";
import { generateText } from "ai";
// Option 1: Use provider with nsec directly
const provider = createNostrAIProvider({
nsec: "nsec1...", // Your Nostr private key
baseURL: "https://shakespeare.diy/v1",
});
// Option 2: Pass a custom signer object
const provider = createNostrAIProvider({
nsec: window.nostr, // NIP-07 signer
baseURL: "https://shakespeare.diy/v1",
});
// Finally, stream or generate text
const { text } = await generateText({
model: provider("claude-sonnet-4.5"),
prompt: "Hello, world!",
});
console.log(text);API
createNostrAIProvider(options)
Creates a new Nostr AI provider instance.
Options
nsec(string, optional): Your Nostr private key in nsec format (bech32-encoded)signer(NostrSigner, optional): A custom Nostr signer implementationbaseURL(string, required): The base URL of your OpenAI-compatible APIfetch(function, optional): Custom fetch implementation- ...all other options from
OpenAICompatibleProviderSettings
Note: Either nsec or signer must be provided.
License
MIT License - see LICENSE file for details
