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 9906 in 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.

Frequently asked questions

What is the difference between logit_bias -100 and a system prompt instruction?

A system prompt instruction can be ignored or worked around if the conversation pressure is high enough. A bias of -100 is enforced at the logit level — the token literally cannot appear in the output regardless of what the model "wants" to say.

Does logit_bias work with all OpenAI models?

It is supported on all chat completion endpoints for GPT-4o, GPT-4, GPT-3.5 Turbo, and the instruct models. It is not available on image, audio, or embedding endpoints. Always check the API reference for the model you are using.

Can I use this with Claude or Gemini?

No. logit_bias is an OpenAI-specific parameter. Anthropic's and Google's APIs do not expose a logit-level bias parameter in the same way. Token-level steering is done via system prompts or structured output constraints on those platforms.

How many tokens can I bias at once?

The OpenAI API accepts up to 300 token IDs in a single logit_bias map. Exceeding this returns a validation error.

Will biasing a token affect subword variants of the same word?

Yes — you need to find and add each variant's token ID separately. For example, " run", "run", "Run", and " Run" are often different tokens (the leading space changes the token ID in most BPE vocabularies). Use the token counter to identify all variants.