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

# Reasoning Models

export const ReasoningModels = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    let attempts = 0;
    const maxAttempts = 50;
    const INIT_DISPLAY_COUNT = 3;
    const interval = setInterval(() => {
      const clientComponent = document.getElementById("reasoning-models");
      if (clientComponent && window.jiekouRemoteData.llmModels.status === 'loaded') {
        const modelList = window.jiekouRemoteData.llmModels.data.filter(model => {
          return (model.features || []).includes('reasoning');
        });
        let displayModels = modelList.slice(0, INIT_DISPLAY_COUNT).map(model => {
          return `<li><span class="model-id-item">${model.id}</span></li>`;
        }).join('');
        let showMoreButton = '';
        if (modelList.length > INIT_DISPLAY_COUNT) {
          showMoreButton = `<button id="show-more-reasoning-model-btn" style="margin-left: 32px; color: rgb(40 116 255)">展示更多</button>`;
        }
        clientComponent.innerHTML = `
          <ul>${displayModels}</ul>
          ${showMoreButton}
        `;
        document.getElementById('show-more-reasoning-model-btn')?.addEventListener('click', () => {
          clientComponent.innerHTML = `
            <ul>${modelList.map(model => {
            return `<li><span class="model-id-item">${model.id}</span></li>`;
          }).join('')}</ul>
          `;
        });
        clearInterval(interval);
      }
      attempts++;
      if (attempts >= maxAttempts) {
        clearInterval(interval);
      }
    }, 200);
    return <div id="reasoning-models"></div>;
  }
};

## Feature Overview

Reasoning models are advanced language models optimized for complex problem-solving and reasoning tasks. They improve answer accuracy by outputting detailed reasoning steps (chain of thought).

### Typical Use Cases

* **Complex problem-solving**: Suitable for scenarios that require step-by-step derivation and clear logical steps, such as mathematics and scientific reasoning.
* **Decision support systems**: Provide detailed reasoning processes to support decision analysis and help users understand the logic behind decisions.
* **Education and training**: Help users learn and understand complex knowledge by providing detailed derivation processes.

## Installation and Preparation

Before using reasoning models, make sure the latest version of the OpenAI SDK is installed:

```bash theme={null}
pip install -U openai
```

## API Usage

Use reasoning models by calling the `/chat/completions` endpoint.

### Request Parameters

* `max_tokens`: Sets the maximum number of tokens in the model output.
* `temperature`: Recommended to set between 0.5 and 0.7 (0.6 recommended) to balance creativity and logical consistency.
* `top_p`: Recommended to set to 0.95.

### Example Request Code

#### Streaming Output Request

```python theme={null}
from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.highwayapi.ai/openai")
messages = [
    {"role": "user", "content": "Explain Newton's second law."}
]

response = client.chat.completions.create(
    model="deepseek/deepseek-r1",
    messages=messages,
    stream=True,
    max_tokens=4096
)

content = ""
reasoning_content = ""
for chunk in response:
    if chunk.choices[0].delta.content:
        content += chunk.choices[0].delta.content
    if chunk.choices[0].delta.reasoning_content:
        reasoning_content += chunk.choices[0].delta.reasoning_content

print("Final answer:", content)
print("Reasoning process:", reasoning_content)
```

#### Non-Streaming Output Request

```python theme={null}
response = client.chat.completions.create(
    model="deepseek/deepseek-r1",
    messages=[
        {"role": "user", "content": "What is the greenhouse effect? How can it be mitigated?"}
    ],
    stream=False,
    max_tokens=4096
)

content = response.choices[0].message.content
reasoning_content = response.choices[0].message.reasoning_content

print("Final answer:", content)
print("Reasoning process:", reasoning_content)
```

## Context Management

The reasoning content returned by the model is not automatically appended to the next turn of the conversation. Users need to manage conversation history manually:

```python theme={null}
messages.append({"role": "assistant", "content": content})
messages.append({"role": "user", "content": "Continue explaining the solution."})
```

## Supported Models

<ReasoningModels />

## Billing

* Billing is based on the number of input and output tokens.
* For specific pricing standards and conversion rules, please check the model details page.

## Notes and Best Practices

* Do not add reasoning instructions in the `system` message. Instead, clearly specify the instructions directly in the `user` message.
* For math problems, clearly state the requirement, such as: "Please reason step by step and clearly state the final answer."
* To prevent the model from skipping the reasoning stage, it is recommended to force the model to add a newline before outputting.
