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

# Reasoning

Reasoning models, such as DeepSeek-R1, systematically process information to derive logical conclusions and solve complex problems step by step. These models are trained to output a long chain of thoughts via reinforcement learning and have the ability to self-correct. This capability transforms AI to move beyond simple response generation, allowing for multi-step reasoning and verification, resulting in more accurate and reflective outputs.

## Model information

DeepSeek R1 is a 671 billion parameter open-source reasoning model. It utilizes tokens specifically for reflecting on how to respond to the user prompt, shown within the `<think>`tags in an output. Due to this difference of structure from typical model requests, consider the following alterations.

### System prompt

* Remove instructional system prompts and minimize additional prompting beyond the user query. Excessive instructions can restrict the model's reasoning scope and reduce output quality.

### User prompt

* Avoid additional chain of thought prompting and explicating how to respond since the model already processes queries in its thinking approach. It's best to use zero-shot or single-instruction plain language prompts for complex tasks. This approach allows the model's internal reasoning capabilities to shine.
* Experiment with the structure of these sections: goal, return format, warnings, and context dump.
* In the rare case the `<think>` tags are bypassed, you can enforce using them by telling the model to start with `<think>` tags.
* To generate concise thinking, the idea of chain-of-draft can be used, that is, such as adding “only keep a minimum draft for each thinking step, with 5 words at most” as a constraint in your prompt.

<img src="https://mintcdn.com/s2gp1o6hatjv6y4/oklJORWUVvpbyEf9/images/docs/buildSN/reasoning-pic.png?fit=max&auto=format&n=oklJORWUVvpbyEf9&q=85&s=5fc6f2fe85025e59c1ea00a5e3233f87" alt="Depiction of reasoning versus non-reasoning model responses." width="1978" height="1178" data-path="images/docs/buildSN/reasoning-pic.png" />

### Parameters

* For general reasoning (non-math reasoning), the suggested `temperature` = 0.6 and `top-p` = 0.95. If you prefer more factual response, `temperature` can be set as smaller one, such as 0.5.
* For math-style reasoning, the suggested `temperature` is 0.7 and `top-p` = 1.0.

## Example request

<CodeGroup>
  ```javascript Javascript
  import OpenAI from "openai";
  const client = new OpenAI({
    baseURL: "your-sambanova-base-url",
    apiKey: "your-sambanova-api-key",
  });
  const chatCompletion = await client.chat.completions.create({
    messages: [
      { role: "system", content: "Answer the question in a couple sentences." },
      { role: "user", content: "I want to understand the factors I should consider when buying a house. For context, I live in California and am 30 years old." },
    ],
    model: "DeepSeek-R1",
  });
  console.log(chatCompletion.choices[0].message.content);
  ```

  ```python Python
  import os
  import openai
  client = openai.OpenAI(
      api_key="your-sambanova-api-key",
      base_url="your-sambanova-base-url",
  )
  response = client.chat.completions.create(
      model="DeepSeek-R1",
      messages=[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"I want to understand the factors I should consider when buying a house. For context, I live in California and am 30 years old."}],
      temperature=0.6,
      top_p=0.95,
      max_tokens= 2500, 
      stream=True
  )
  for chunk in response:
    print(chunk.choices[0].delta.content, end="")
  ```

  ```bash Curl
  export API_KEY="your-api-key-here"
  export URL="your-url-here"

  curl -H "Authorization: Bearer $API_KEY" \
       -H "Content-Type: application/json" \
       -d '{
  	"stream": true,
  	"model": "DeepSeek-R1",
  	"messages": [
  		{
  			"role": "system",
  			"content": "You are a helpful assistant"
  		},
  		{
  			"role": "user",
  			"content": "I want to understand the factors I should consider when buying a house. For context, I live in California and am 30 years old."
  		}
  	]
  	}' \
       -X POST $URL
  ```
</CodeGroup>

## Use cases

### Report generator

DeepSeek-R1 is particularly adept at processing unstructured information, making it ideal for analyzing complex documents like legal contracts, financial statements, or scientific papers. Reasoning models can facilitate pattern recognition by analyzing multiple facets of the information, prior to distilling it into a comprehensive summary.

**Example prompt**

`Develop a comprehensive report on the state of autonomous vehicles. Present this report with organized sections and a breif summarization. Be careful to cite the achievements with the proper entity that made that achievement or contribution. For context: I am knowledgable in this field and have a technical understanding of autonmous vehicle systems. I've been working most of my career in artificial intelligence but have not yet joined a company with the sole focus of autonomous vehicles. I am considering making the career change and wanted to understand the current ecosystem before I go through the job search process.`

### Planner for workflows and agents

Reasoning models excel at tackling ambiguous and complex tasks. They can break down intricate problems, strategize solutions, and make decisions based on large volumes of ambiguous information. Use DeepSeek-R1 as a strategic planner for complex, multi-step problems. It can break down tasks, develop detailed solutions, and even orchestrate other AI models for specific subtasks within an agentic system.

To visualize the vast capabilities of thoughtful planning in a powerful workflow, the demo app  implements DeepSeek-R1 as a planner. It orchestrates agents with various workflows, such as Deep Research, Financial Analysis, and Sales Leads. The app is open-source allowing developers quick experimentation and easy production of their own agent workflows within the system.

<img src="https://mintcdn.com/s2gp1o6hatjv6y4/oklJORWUVvpbyEf9/images/agent_demp.png?fit=max&auto=format&n=oklJORWUVvpbyEf9&q=85&s=da1c1b74704e571736d309b06d588672" alt="" width="2560" height="1153" data-path="images/agent_demp.png" />

### Coding and mathematical guru

These models are effective at reviewing and improving code. They can detect minor changes in a codebase that might be missed by human reviewers. In solving math problems, reasoning is helpful to breakdown tasks into many steps and verify its work throughout solving.

## Best Practices

<AccordionGroup>
  <Accordion title="Latency and cost" defaultOpen="true">
    Reasoning model outputs have higher latency and token usage with its `<think>` process, so consider using non-reasoning models for simpler tasks to optimize for budget and response time needs. It’s features have advantages of considering a user prompt more holistically, but also takes up token capacity and time to produce a complete answer. Developers should apply the powerful model in optimal situations for its response approach.
  </Accordion>

  <Accordion title="Streaming" defaultOpen="false">
    Enabling streaming can improve user experience in applications using DeepSeek-R1. Due to the longer process of generation, this feature confirms the reduces ambiguity and anticipation by displaying tokens as they are available. Implement this by adding the parameter `stream=True` into the model request.
  </Accordion>

  <Accordion title="Function calling" defaultOpen="false">
    DeepSeek-R1 the current enablement of function calling is unstable, occasionally resulting in looped calls or empty responses having as noted in the [DeepSeek documentation](https://api-docs.deepseek.com/guides/function_calling). Prompt engineering can be implemented as a workaround with trial and error, but using a different model would be optimal. Learn more about function calling with models like Llama-3.3-70B by viewing the [Function calling and JSON mode](/en/features/function-calling) document.
  </Accordion>
</AccordionGroup>

## FAQs

<AccordionGroup>
  <Accordion title="I got BadRequestError: 400 about the maximum context length of DeepSeek-R1. Where can I check this information?">
    Check the [SambaCloud models](/en/models/sambacloud-models) page for more information on the current context length of the model. Also feel free to reach out about any errors in our [Community](https://community.sambanova.ai/?_gl=1*1701fpm*_gcl_au*MjQyOTk0NDQ2LjE3Mzg2OTQ3Njk.*_ga*MTI0MzQ0NzAyNS4xNzIzMDcwMzgx*_ga_2D4J2VB6SX*MTc0MTI4NjkzNC4zOTMuMS4xNzQxMjg5NDc2LjYwLjAuMA..).
  </Accordion>

  <Accordion title="If the model was created by a Chinese company, where is it being hosted?">
    We are hosting the model primarily in US-based data centers, with some additional data centers in Japan.
  </Accordion>

  <Accordion title="How can I access it?">
    Try the model in our [Playground](https://cloud.sambanova.ai/) and then get an [API key](https://cloud.sambanova.ai/apis) to get access as it becomes available.
  </Accordion>
</AccordionGroup>
