Search IOCombats

Search challenges, guides, questions and articles

Ai Interview Questions

Browse through all 20 Ai interview questions and challenges below.

Type:
Sort:
Difficulty:

First treat the key as leaked: rotate it in the provider dashboard, because NEXT_PUBLIC_ values are inlined into the JavaScript bundle at build time. Then move the model call into a Route Handler, store the key in a variable without the NEXT_PUBLIC_ prefix, and import "server-only" in the module that uses it so a Client Component import fails the build. The browser only talks to your route, which adds auth and limits before calling the provider.

beginnerai sdkaisecuritynextjs

At each step the model produces a probability for every possible next token, and temperature reshapes that distribution before one token is sampled. Lower temperature makes the likeliest tokens even more likely, so output is more focused and repeatable; higher temperature flattens it, so output is more varied. Lower it for extraction, classification and code, but check your model first: several newer models only accept the default value.

beginnerllm fundamentalsaillmtemperature

A token is the unit of text a model reads and writes: usually a word, part of a word, a punctuation mark or a space-plus-word chunk. Providers bill and rate-limit by tokens, not characters or words, so the same text can cost different amounts on models with different tokenizers. Count tokens with the provider's tokenizer or counting API instead of guessing from string length.

beginnerllm fundamentalsaillmtokens

useChat keeps an array of UIMessage objects, each with an id, a role and a list of parts. sendMessage adds your message right away, sets status to submitted, posts the conversation through a transport and then applies each streamed chunk to the assistant message, moving status to streaming and finally to ready or error. Helpers like stop, regenerate and setMessages change that same array, and the throttle option limits how often React re-renders.

intermediateai sdkaireactai-sdk

The server owns everything that must be trusted: the API key, the model choice, the system instructions, tool execution, auth, input validation, rate limits and saving the conversation. The client owns everything the user touches: the input box, the message list, rendering streamed parts, the stop button and loading or error states. In the App Router that usually means a Route Handler that returns a UI message stream and a Client Component that uses useChat.

intermediateai sdkainextjsai-sdk

An AI SDK gives you one API (generateText, streamText, tools, structured output and a UI message stream) on top of a shared language model specification, so switching providers is mostly a change to the model argument. What stays provider-specific is capability and behaviour: which models support tools, images or reasoning, how they tokenize and price, features like prompt caching, and extra settings you pass through providerOptions keyed by provider name.

intermediateai sdkaiai-sdkvercel

Follow the stream only while the user is already at the bottom. Track a "stick to bottom" flag from scroll position, turn it off as soon as the user scrolls up, and show a "Jump to latest" button instead of pulling them back down. Scroll when the content actually grows (a ResizeObserver on the message container works well), and turn sticking back on when the user sends a new message or clicks the button.

intermediatestreaming uiaireactscroll

Keep finished messages stable and isolate the one that is still streaming, so only that bubble re-renders. Wrap message rows in React.memo with stable keys and unchanged object references, and batch incoming chunks so you update state at most once per animation frame instead of once per token.

intermediatestreaming uiaireactperformance

Render markdown to React elements with a library like react-markdown, which escapes raw HTML by default, instead of piping parsed HTML into dangerouslySetInnerHTML. To avoid flicker and wasted work, split the text into blocks and memoize finished blocks so only the last one re-parses, and handle unclosed syntax such as an open code fence, either yourself or with a streaming-aware renderer like Streamdown.

intermediatestreaming uiaimarkdownxss

Model each assistant reply as a message with a status (streaming, done, stopped or error) and a list of versions. Stop aborts the request and marks the current version as stopped while keeping its text. Regenerate rebuilds the history up to the user message before that reply, streams a new version into the same message slot, and keeps older versions available so nothing the user saw is silently lost.

intermediatestreaming uiaireactstate-management

The context window is the maximum number of tokens a model can work with in one request: system prompt, chat history, documents, tools and the answer it generates. The model has no memory between calls, so your app resends the history every turn and it keeps growing. When the input is too large the API rejects the request, so the app must trim, summarize or compact older turns before that happens.

intermediatellm fundamentalsaillmcontext-window

Input tokens are everything you send; output tokens are what the model generates. Output is priced higher per token (Anthropic currently lists it at 5x input for its Claude models), and it is generated one token at a time, so long answers dominate total response time. Long inputs cost more and delay the first token, but caching repeated prefixes can make that input much cheaper.

intermediatellm fundamentalsaillmpricing

LLMs sample each next token from a probability distribution, so two runs of the same prompt can take different paths, and even temperature 0 is not fully deterministic. Model updates and changes to the hidden context (system prompt, history, retrieved data) change answers too. The UI should treat every response as a unique record: store what the user saw, offer regenerate instead of hiding variation, and validate anything the app depends on.

intermediatellm fundamentalsaillmnondeterminism

Create an AbortController per request, pass controller.signal to fetch, and call controller.abort() from the Stop button or a useEffect cleanup. The fetch promise or the pending reader.read() then rejects with an AbortError, which you catch and treat as a normal stop, keeping the text already shown. On the server, pass the incoming request signal on to the upstream LLM call so the model actually stops generating and billing.

intermediatestreamingaistreamingabortcontroller

response.body is a ReadableStream of Uint8Array chunks. Get a reader with getReader(), call read() in a loop until done is true, and turn each chunk into text with a single TextDecoder using decode(chunk, { stream: true }). Then buffer the text and parse only complete lines or events, because network chunks do not line up with tokens or messages.

intermediatestreamingaistreamingreadablestream

For a normal chat completion, Server-Sent Events (SSE) over HTTP is the better fit: the client sends one request, the server pushes tokens back in one direction, and it works with ordinary HTTP infrastructure, auth and serverless functions. The major LLM APIs stream over SSE for exactly this reason. WebSockets make sense when both sides need to keep sending data over one long-lived connection, such as realtime voice or a persistent agent session.

intermediatestreamingaistreamingserver-sent-events

Limit in layers, inside the Route Handler and before the model call. Identify the caller by user id (IP only as a fallback), apply a request limit such as a sliding window in Redis, and add a daily token budget per user because one request can cost far more than another. Cap input size and maxOutputTokens, return 429 with a Retry-After header when a limit is hit, and show a calm message in the UI.

advancedai sdkairate-limitingnextjs

Do not let the screen reader announce the answer token by token. Keep the streaming text out of an active live region, and use a separate, visually hidden polite status region to announce short lifecycle messages such as "Generating response" and "Response complete". Keep focus in the input, give each message a clear structure the user can navigate, and test with real screen readers because live region support varies.

advancedstreaming uiaiaccessibilityaria-live

Start the upstream request, then hand its body stream straight to your response instead of awaiting text() or json(). In a Next.js Route Handler that means returning new Response(upstream.body); in Express, pipe Readable.fromWeb(upstream.body) into res. Then remove hidden buffers along the path (compression middleware, nginx proxy buffering, caches) and abort the upstream call when the client disconnects.

advancedstreamingaistreamingnodejs

UTF-8 encodes many characters in 2 to 4 bytes, and the network can split a stream anywhere, including in the middle of one character. If you decode each chunk on its own, the incomplete bytes become the replacement character U+FFFD. Use one TextDecoder for the whole stream with decode(chunk, { stream: true }) (or TextDecoderStream), and flush it at the end, so incomplete bytes wait for the next chunk.

advancedstreamingaistreamingutf-8