Concept beginner · 3 min read

What is seed parameter in OpenAI API

Quick answer
The seed parameter in the OpenAI API is used to initialize the random number generator for deterministic outputs, ensuring reproducible completions. Setting a fixed seed makes the model produce the same response for identical inputs across calls.
Seed parameter is a numeric value that initializes the random number generator in the OpenAI API to produce deterministic and reproducible outputs.

How it works

The seed parameter acts like a starting point for the model's internal randomness. Think of it as setting the initial state of a random number generator. When you provide the same seed along with the same prompt and parameters, the model's output will be consistent and repeatable. Without a fixed seed, the model's responses can vary due to inherent randomness in sampling methods like temperature and top-p.

Concrete example

Below is a Python example using the OpenAI SDK v1 showing how to set the seed parameter to get reproducible completions with gpt-4o:

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

response1 = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a haiku about spring."}],
    seed=12345
)

response2 = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a haiku about spring."}],
    seed=12345
)

print(response1.choices[0].message.content)
print("---")
print(response2.choices[0].message.content)
output
Gentle spring breezes
Cherry blossoms softly fall
New life awakens
---
Gentle spring breezes
Cherry blossoms softly fall
New life awakens

When to use it

Use the seed parameter when you need consistent, reproducible outputs for testing, debugging, or caching results. It is ideal for scenarios where deterministic behavior is critical, such as automated grading, regression tests, or generating repeatable content. Avoid using seed when you want diverse or creative outputs, as fixing the seed reduces randomness and variation.

Key Takeaways

  • The seed parameter controls randomness to produce repeatable outputs.
  • Set seed for debugging, testing, or caching identical completions.
  • Do not use seed if you want varied or creative responses.
  • The seed value must be an integer and consistent across calls for reproducibility.
Verified 2026-04 · gpt-4o
Verify ↗