> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inputapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generation parameters and logprobs

> Understand model and channel limits for sampling, penalties, seeds, and token probabilities.

## Choose parameters

| Chat field | Purpose | Boundary |
| - | - | - |
| `temperature` / `top_p` | Adjust sampling | Tune one first; ranges and support depend on the model; zero temperature does not guarantee identical results |
| `seed` | Request best-effort reproducibility | A fixed seed cannot fix model versions, routing, or backend implementation |
| `frequency_penalty` / `presence_penalty` | Adjust repetition tendency | Model dependent; zero should not mean omitted |
| `logit_bias` | Adjust sampling for particular tokens | Token IDs depend on the target tokenizer, not a universal vocabulary |
| `logprobs` / `top_logprobs` | Request generated-token and candidate log probabilities | Requires model support; candidate count need not equal the requested value |
| `max_tokens` / `max_completion_tokens` | Limit generation | Do not blindly set both; see [reasoning models](/en/guides/reasoning-models) |

The DTO uses pointers for most optional sampling fields to distinguish omission from `0` / `false`. However, the OpenAI adapter can remove unsupported `temperature`, `top_p`, `logprobs`, and `top_logprobs` according to model capabilities. HTTP success does not prove every parameter took effect. Do not copy Chat's seed, penalty, and logprobs example directly into Responses.

## Read logprobs

Non-streaming Chat places metadata in `choices[].logprobs.content`: entries contain `token`, `logprob`, optional `bytes`, and `top_logprobs`. This describes token sampling, not answer correctness or factual accuracy; very-low-probability sentinel values are not precise probabilities. Streaming metadata sits in each choice's `logprobs`, outside `delta.content`; accumulate it by choice and order.

Ordinary OpenAI response forwarding retains raw fields. Channel `ForceFormat` rebuilding or protocol conversion does not guarantee preservation of extra logprobs metadata. If missing, check model support, request filtering, and the actual response path.

The example explicitly sends zero values and requests two alternatives. It requires completed text and nonempty token metadata, permits empty alternative arrays, and does not require an exact alternative count. It validates finite nonpositive numbers, byte ranges, and refusal/tool/truncation states before printing text and token probabilities, excluding raw responses and reasoning fields. One request without retries; local tests do not establish upstream reproducibility or probability quality.

Implementation sources: `relaykit/dto/openai_request.go`, `relay/channel/openai/adaptor.go`, and `relay/channel/openai/relay-openai.go`. See [Chat API](/en/api-reference/chat-completions) and [parameter filtering](/en/guides/data-controls).

## Run the example

Run from the documentation directory with approved inputs and a capable model; first read the [REST runtime](/en/guides/http-runtime). Keep the script and `http-client.mjs` together.

```sh theme={null}
export API_ROOT_URL='https://gateway.example.com'
export API_KEY='YOUR_API_KEY'
export API_MODEL='YOUR_LOGPROBS_MODEL_ID'
node examples/logprobs.mjs
```

```javascript theme={null}
import { requestJSON } from './http-client.mjs';

try {
  const model = process.env.API_MODEL;
  if (!model?.trim()) throw new Error('Set model.');
  const result = await requestJSON('/v1/chat/completions', {
    model, messages: [{ role: 'user', content: 'Reply with the word hello.' }],
    temperature: 0, seed: 0, frequency_penalty: 0, presence_penalty: 0,
    logprobs: true, top_logprobs: 2,
  });
  const choice = result.choices?.[0];
  const message = choice?.message;
  if (!Array.isArray(result.choices) || result.choices.length !== 1 || choice?.index !== 0
    || choice.finish_reason !== 'stop' || message?.role !== 'assistant'
    || message.refusal != null || message.tool_calls != null || message.function_call != null
    || typeof message.content !== 'string' || !message.content.trim()) throw new Error('Incomplete text.');
  const tokens = choice.logprobs?.content;
  if (!Array.isArray(tokens) || !tokens.length) throw new Error('Missing logprobs.');
  const observations = [];
  for (const token of tokens) {
    if (!Array.isArray(token?.top_logprobs)) throw new Error('Missing alternatives.');
    for (const value of [token, ...token.top_logprobs]) {
      if (typeof value?.token !== 'string' || typeof value.logprob !== 'number'
        || !Number.isFinite(value.logprob) || value.logprob > 0
        || (value.bytes != null && (!Array.isArray(value.bytes)
          || value.bytes.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255)))) {
        throw new Error('Invalid token metadata.');
      }
    }
    observations.push({ token: token.token, logprob: token.logprob,
      top_logprobs: token.top_logprobs.map(({ token, logprob }) => ({ token, logprob })) });
  }
  console.log(JSON.stringify({ text: message.content, tokens: observations }));
} catch {
  console.error('Logprobs example failed. Check model support, retained metadata, and completion status. No automatic retry.');
  process.exitCode = 1;
}
```

[阅读中文](/zh/guides/generation-parameters)

[Related guide: Predicted outputs](/en/guides/predicted-outputs)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.