# Reasoning

URL: https://interfaze.ai/docs/reasoning

Reasoning allows the model to think deeply using more compute and thinking tokens to solve more complex problems like in math, science, etc.

Reasoning is turned off by default as most use cases don't require it for deterministic responses like OCR, Translation, etc. but can be turned on by setting the `reasoning_effort` to `high`.

## How to use reasoning

```tabs
language-typescript

tab-OpenAI SDK
const response = await interfaze.chat.completions.create({
  model: "interfaze-beta",
  messages: [
    {
      role: "user",
      content: "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors."
    }
  ],
  reasoning_effort: "high",
});

console.log(response?.reasoning);
console.log(response.choices[0].message.content);
tab-Vercel AI SDK
import { generateText } from 'ai';

const { text, reasoning } = await generateText({
  model: interfaze.chat("interfaze-beta"),
  prompt: "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors.",
  providerOptions: {
    openai: {
      reasoningEffort: "high",
    },
  },
});

console.log(reasoning);
console.log(text);
tab-LangChain SDK
import { ChatOpenAI } from "@langchain/openai";

const interfaze = new ChatOpenAI({
  configuration: {
    baseURL: "https://api.interfaze.ai/v1",
  },
  apiKey: "<your-api-key>",
  model: "interfaze-beta",
  reasoning: {
    effort: "high",
  },
});

const response = await interfaze.invoke(
  "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors."
);

console.log(response.content);
language-python

tab-OpenAI SDK
response = interfaze.chat.completions.create(
    model="interfaze-beta",
    messages=[
        {
            "role": "user",
            "content": "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors."
        }
    ],
    reasoning_effort="high"
)

print(getattr(response, "reasoning", None))
print(response.choices[0].message.content)
tab-LangChain SDK
from langchain_openai import ChatOpenAI

interfaze = ChatOpenAI(
    base_url="https://api.interfaze.ai/v1",
    api_key="<your-api-key>",
    model="interfaze-beta",
    reasoning_effort="high"
)

response = interfaze.invoke(
    "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors."
)
print(response.content)
```

## Reasoning in streaming mode

When using streaming mode with reasoning enabled, the reasoning process is delivered as it happens, wrapped between `<think>` and `</think>` tags.

```tabs
language-typescript

tab-OpenAI SDK
const stream = await interfaze.chat.completions.create({
  model: "interfaze-beta",
  messages: [
    {
      role: "user",
      content: "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors."
    }
  ],
  reasoning_effort: "high",
  stream: true,
});

for await (const chunk of stream) {
  const content = chunk.choices[0]?.delta?.content;
  if (content) {
    process.stdout.write(content);
  }
}
tab-Vercel AI SDK
import { streamText } from 'ai';

const { textStream } = await streamText({
  model: interfaze.chat("interfaze-beta"),
  prompt: "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors.",
  providerOptions: {
    openai: {
      reasoningEffort: "high",
    },
  },
});

for await (const delta of textStream) {
  process.stdout.write(delta);
}
tab-LangChain SDK
import { ChatOpenAI } from "@langchain/openai";

const interfaze = new ChatOpenAI({
  configuration: {
    baseURL: "https://api.interfaze.ai/v1",
  },
  apiKey: "<your-api-key>",
  model: "interfaze-beta",
  streaming: true,
  reasoning: {
    effort: "high",
  },
});

const stream = await interfaze.stream(
  "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors."
);

for await (const chunk of stream) {
  process.stdout.write(chunk.content as string);
}
language-python

tab-OpenAI SDK
stream = interfaze.chat.completions.create(
    model="interfaze-beta",
    messages=[
        {
            "role": "user",
            "content": "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors."
        }
    ],
    reasoning_effort="high",
    stream=True
)

for chunk in stream:
    if not chunk.choices:
        continue
    delta = chunk.choices[0].delta
    if delta and delta.content is not None:
        print(delta.content, end="", flush=True)
tab-LangChain SDK
from langchain_openai import ChatOpenAI

interfaze = ChatOpenAI(
    base_url="https://api.interfaze.ai/v1",
    api_key="<your-api-key>",
    model="interfaze-beta",
    streaming=True,
    reasoning_effort="high"
)

for chunk in interfaze.stream(
    "Explain why renewable energy is important for combating climate change. Consider economic, environmental, and social factors."
):
    print(chunk.content, end="", flush=True)
```

The reasoning chunks stream chunk by chunk, allowing you to display the thought process in real-time before the final answer arrives.

```xml
<think>
Reasoning chunk 1...
Reasoning chunk 2...
Reasoning chunk 3...
</think>

Final answer begins here...
```
