log probabilities (logprobs)
Log probabilities, or logprobs, are the natural logarithms of the probabilities that a large language model assigns to each token it generates. Many model APIs can return them alongside the generated text.
At each step of autoregressive generation, the model scores every token in its vocabulary given the context so far. A logprob is zero or negative. A value of 0.0 means the model was certain, and values further below zero mean it considered the token less likely. Logs keep tiny probabilities readable and turn the probability of a whole sequence into a simple sum.
In the explorer below, selecting a token in a sample reply shows its logprob and the top alternatives the model weighed at that position. The chosen tokens’ logprobs also add up to a score for the whole reply:
APIs such as OpenAI’s Chat Completions return the logprob of each chosen token when you set the logprobs parameter. With top_logprobs, they can also list up to 20 top alternatives at every position. Common uses include the following:
- Flagging low-confidence answers as possible hallucinations
- Reading the probability behind a one-token classification label
- Computing perplexity or ranking candidate completions during evaluation
Provider support varies, and some APIs reject the parameter outright. Logprobs also measure only the model’s own certainty, which can be high for a wrong answer.
Related Resources
Course
Leverage OpenAI's API in Your Python Projects
Learn how to use the ChatGPT API with Python's openai library to send prompts, control AI behavior with roles, and get structured outputs.
For additional information on related topics, take a look at the following resources:
- Prompt Engineering: A Practical Example (Tutorial)
- Build an LLM RAG Chatbot With LangChain (Tutorial)
- Pydantic AI: Build Type-Safe LLM Agents in Python (Tutorial)
- Building Type-Safe LLM Agents With Pydantic AI (Course)
- Practical Prompt Engineering (Quiz)
- First Steps With LangChain (Course)
- Build an LLM RAG Chatbot With LangChain (Quiz)
- Pydantic AI: Build Type-Safe LLM Agents in Python (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Martin Breuss • Updated Nov. 6, 2026