How to get repeatable results using seed

The seed parameter lets you make model outputs deterministic — meaning you’ll get the same output every time for the same prompt and settings.

Great for testing, debugging, or consistent experiences in production.

What it does:

  • When you pass a seed, the model uses that value to initialize its random number generator.
  • This allows it to sample deterministically — so the same prompt and settings will always produce the same result.
  • If you don’t pass a seed, the output will naturally vary on each request.
  • Note: This feature is currently in Beta — the system will make a best effort to sample deterministically when seed is used.

Format and Range:

PropertyValue TypeRange
seedInteger>= -9223372036854776000 to <= 9223372036854776000

👉 Typically, values like 42, 1234, or any stable number will work fine.

When to use seed:

Use CaseWhy use it?
Regression testingEnsure same outputs over time
Demo apps or tutorialsShow consistent results to all users
A/B testing with fixed inputsKeep output stable for comparison
QA pipelinesValidate expected model behavior

1# Install SarvamAI
2!pip install -Uqq sarvamai
3from sarvamai import SarvamAI
1# Initialize the SarvamAI client with your API key
2client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
1# Example: Using `seed` to repeat responses
2
3response = client.chat.completions(
4 messages=[
5 {"role": "system", "content": "You are a poetry assistant."},
6 {"role": "user", "content": "Write a short poem about the moon."}
7 ],
8 seed=12345 # Ensures the same poem is returned every time (best effort)
9)
1# Receive assistant's reply as output.
2print(response.choices[0].message.content)