OpenAI-compatible provider with Nostr NIP-98 auth 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.
- 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
``bash`
npm i nostr-ai-provider
`typescript
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);
`
Creates a new Nostr AI provider instance.
#### Options
- nsec (string, optional): Your Nostr private key in nsec formatsigner
(bech32-encoded)
- (NostrSigner, optional): A custom Nostr signer implementationbaseURL
- (string, required): The base URL of your OpenAI-compatible APIfetch
- (function, optional): Custom fetch implementationOpenAICompatibleProviderSettings
- ...all other options from
Note: Either nsec or signer` must be provided.
MIT License - see LICENSE file for details