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

First, install the SDK:

$pip install -Uqq sarvamai

Then use the following Python code:

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