OpenAI logit_bias Builder
Build the logit_bias JSON object for OpenAI API calls. Add token IDs, drag the slider from −100 (effectively bans the token) to +100 (strongly boosts it), and copy the resulting map. Token IDs are integers — use the OpenAI token counter to find the ID for a specific word or subword.
How to use the OpenAI logit_bias Builder
Click Add token to add a row. Each row has:
- Token ID — a positive integer. Use the OpenAI token counter to look up the token ID for a word or subword. For example, "Hello" is token
9906in cl100k_base. - Bias slider (−100 to 100) — negative values suppress the token; positive values boost it. The number mirror updates in sync with the slider.
- Remove button — deletes that row.
Click Build JSON (or it auto-rebuilds on any change) to generate the {"token_id": bias} map. Any row with a non-integer token ID is skipped and flagged. Copy the result and pass it as the logit_bias parameter in your API call:
openai.chat.completions.create(model="gpt-4o", messages=[...], logit_bias={"9906": -100})
How logit_bias works
When an LLM generates text, it computes a probability distribution over its entire vocabulary at each token step. Before applying softmax, the raw per-token scores are called logits. The logit_bias parameter lets you add a constant offset to specific tokens' logits before that final softmax — which shifts their probability up or down. A bias of -100 makes a token so unlikely the model effectively never generates it; +100 makes it overwhelmingly preferred. Values between ±1 and ±10 produce more subtle, controllable steering.
The parameter takes token IDs (integers), not words or subwords. This is because a single English word like "run" may tokenise differently depending on context, preceding punctuation, or capitalisation. To find the token IDs you care about, use the OpenAI token counter, which shows the numeric ID for every token in a piece of text.
Common use cases: ban profanity tokens (bias -100), force the model to prefer a company name over alternatives, constrain output to a fixed set of tokens (e.g., "Yes"/"No"), or subtly boost tokens related to a topic without changing the system prompt. Because logit bias operates post-inference at the logit level, it has zero impact on latency — unlike a longer system prompt. The trade-off is that you must think at the token level, not the word level, and biasing too aggressively can produce incoherent output.
Common use cases
- Content moderation — ban specific offensive-word tokens at the API layer, guaranteeing they never appear regardless of prompt.
- Forced structured output — boost "true"/"false" or "yes"/"no" tokens when you need a binary answer without a full JSON-mode call.
- Brand safety — suppress competitor names or trademarked terms from appearing in AI-generated copy.
- Domain steering — gently boost technical vocabulary tokens to keep a coding assistant on-topic.
- Output format control — suppress newline and Markdown tokens when you need plain prose with no headers or bullets.