Skip to content

Get Log Probs #251

Description

@davide221

Is there some way to get all the log probs of multiple possible next tokens with the library? So far I managed to get only the probabilities for the chosen token with this example

curl -X POST https://api.together.xyz/v1/chat/completions \
     -H 'Content-Type: application/json' \
     -H "Authorization: Bearer $TOGETHER_API_KEY"\
     -d '{
     "model": "codellama/CodeLlama-70b-Instruct-hf",
     "stream": false,
     "max_tokens": 10,
     "messages": [
       {"role": "user", "content": "write an async function in python"}
     ],
     "logprobs": 1
 }'

{
  "id": "85d3d3ff1a0d8c57-EWR",
  "object": "chat.completion",
  "created": 1709240335,
  "model": "codellama/CodeLlama-70b-Instruct-hf",
  "prompt": [],
  "choices": [
    {
      "finish_reason": "length",
      "logprobs": {
        "tokens": [
          "1",
          ".",
          " Define",
          " the",
          " function",
          " with",
          " the",
          " async",
          " keyword",
          "."
        ],
        "token_logprobs": [
          -1.0029297,
          -0.07861328,
          -2.1367188,
          -0.921875,
          -0.6479492,
          -1.1318359,
          -0.35668945,
          -0.6743164,
          -0.023162842,
          -1.1484375
        ]
      },
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "1. Define the function with the async keyword."
      }
    }
  ],
  "usage": {
    "prompt_tokens": 33,
    "completion_tokens": 10,
    "total_tokens": 43
  }
}

Activity

Ranoobaba commented on Jul 21, 2026

@Ranoobaba

Hi! The API already supports this: pass logprobs=k (an integer from 0 to 20) and each choice's logprobs part carries per token top_logprobs, which is a list with one {token: logprob} dict per generation step (see #452, which adds the typed response field). I opened PR #455 that makes it discoverable and safe from the request side: it documents the [0, 20] range in the create() docstrings, rejects out of range values with a clear error before the request is sent, and adds a regression test pinning that top_logprobs round trips through model_dump() without Pydantic warnings. Thanks, Rayyan

blainekasten commented on Sep 15, 2026

@blainekasten
Contributor

This repo is deprecated and is not taking new patches. Thanks.

The new SDK is hosted at https://github.com/togethercomputer/together-py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions