AI-20AINew, October 21, 2026
AI Token Alternatives
An answer where every unsure word shows what else the model weighed. Pick another word and the reply writes itself again from there.
Usage
The alternatives come from your model's logprobs: the other words it nearly wrote at each step. fromLogprobs turns an OpenAI-style logprobs.content list into the answer, making a slot of every word where another one was at least 8% likely, and keeping the real probability of every other word for the confidence view.
Pass compose and it's called with the word picked in each slot. Ask the model again from that point and return the new answer, or a Promise of it: the words up to the pick stay, and the rest is written again once it lands. A throw shows the error's message under the answer.
"use client";
import AITokenAlternatives, { fromLogprobs } from "@/components/kokonutui/ai-token-alternatives";
export function Reply({ question }: { question: string }) {
return (
<AITokenAlternatives
compose={async (choice, signal) => {
const res = await fetch("/api/alternatives", {
method: "POST",
body: JSON.stringify({ question, choice }),
signal,
});
if (!res.ok) {
throw new Error("Couldn't reach the model. Try another word.");
}
const { logprobs } = await res.json();
return fromLogprobs(logprobs);
}}
prompt={question}
/>
);
}// app/api/alternatives/route.ts
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
export async function POST(req: Request) {
const { question, choice } = await req.json();
const { providerMetadata } = await generateText({
model: openai("gpt-4.1-mini"),
prompt: question,
// Your choice of words so far, as a prefix the model continues from.
system: Object.keys(choice).length ? `Keep these words: ${Object.values(choice).join(", ")}` : undefined,
providerOptions: { openai: { logprobs: 4 } },
});
return Response.json({ logprobs: providerMetadata?.openai?.logprobs ?? [] });
}Slot ids from fromLogprobs follow token positions (t0, t1…), so the words before a pick keep their ids from one take to the next.
PROSlash Command Menu and more like it are in Kokonut UI Pro
Installation
AI Token Alternatives is a free, open-source React component in the Kokonut UI AI collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/ai-token-alternatives.tsx, so the code is yours to change.
npx shadcn@latest add @kokonutui/ai-token-alternativesOr add it by hand: install its packages, then copy the source from Copy code above into components/kokonutui/ai-token-alternatives.tsx.
npm install lucide-react motionProps
promptstringThe user's message, drawn as a bubble. Only the demo draws one by default.
slotsTokenSlot[]The words with alternatives. compose can return new ones instead.
compose(choice: Record<string, string>, signal: AbortSignal) => ComposedAnswer | Promise<ComposedAnswer>Builds the answer from the word picked in each slot. Return it or a Promise of it: after a pick, the words up to that one stay and the rest is written again once it arrives. signal aborts when another pick replaces this one. Throw and the answer shows the error's message.
classNamestringExtra classes for the root element.
TokenSlot
idrequiredstringoptionsrequiredTokenOption[]Most likely first. The first one is what the model wrote.
ComposedAnswer
An answer, with its own slots when they change from one take to the next.
type ComposedAnswer =
| AnswerPiece[]
| { pieces: AnswerPiece[]; slots: TokenSlot[] };TokenOption
textrequiredstringprequirednumberHow likely the model was to pick this word, from 0 to 1.
AnswerPiece
Plain text, plain text with the model's probability for it, or a word the model nearly wrote differently.
type AnswerPiece =
| string
| { text: string; p: number }
| { slot: string };Dependencies
| Needs | Version | Comes from |
|---|---|---|
lucide-react | ^0.556.0 | npm, installed by the CLI |
motion | ^12.23.25 | npm, installed by the CLI |
cn from lib/utils.ts | shadcn init | |
| React | 19 | Your app |
| Tailwind CSS | 4 | Your app |
No provider, font or global CSS to set up: the file works as soon as it lands.

