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

# Reasoning

> Advanced reasoning capabilities

The reasoning capabilities in Sudo allow you to access advanced reasoning models like o3 for complex problem-solving tasks.

## Basic Reasoning

<Note> `reasoning_effort` parameter is mainly supported for OpenAI models. While other providers have reasoning models as well, not all providers support `reasoning_effort` </Note>

### Simple Reasoning Task

<CodeGroup dropdown>
  ```typescript TypeScript theme={null}
  import { Sudo } from "sudo-ai";

  const sudo = new Sudo({
    serverURL: "https://sudoapp.dev/api",
    apiKey: process.env.SUDO_API_KEY ?? "",
  });

  async function simpleReasoningTask() {
    try {
      const response = await sudo.router.create({
        model: "o3",  // Reasoning model
        messages: [
          {
            role: "user",
            content: "Solve this step by step: If a train travels 120 km in 2 hours, and then 180 km in 3 hours, what is its average speed for the entire journey?"
          }
        ]
      });
      
      console.log("Reasoning Response:");
      console.log(response.choices[0].message.content);
      
    } catch (error) {
      console.error("Reasoning error:", error);
    }
  }

  simpleReasoningTask();
  ```

  ```python Python theme={null}
  import os
  from sudo import Sudo

  with Sudo(
      server_url="https://sudoapp.dev/api",
      api_key=os.getenv("SUDO_API_KEY"),
  ) as client:
      response = client.router.create(
          model="o3",  # Reasoning model
          messages=[
              {
                  "role": "user",
                  "content": "Solve this step by step: If a train travels 120 km in 2 hours, and then 180 km in 3 hours, what is its average speed for the entire journey?"
              }
          ]
      )
      
      print("Reasoning Response:")
      print(response.choices[0].message.content)
  ```
</CodeGroup>

### Reasoning Effort Levels (OpenAI models)

<CodeGroup dropdown>
  ```typescript TypeScript theme={null}
  import { Sudo } from "sudo-ai";

  const sudo = new Sudo({
    serverURL: "https://sudoapp.dev/api",
    apiKey: process.env.SUDO_API_KEY ?? "",
  });

  async function solveWithDifferentEfforts(problem: string): Promise<void> {
    // Effort levels to control reasoning depth
    const efforts: Array<"low" | "medium" | "high"> = ["low", "medium", "high"];
    
    try {
      for (const effort of efforts) {
        console.log(`\n--- Reasoning Effort: ${effort.toUpperCase()} ---`);
        
        const response = await sudo.router.create({
          model: "o3",
          messages: [
            { role: "user", content: problem }
          ],
          reasoningEffort: effort
        });
        
        console.log(response.choices[0].message.content);
        
        // Show token usage for different efforts
        if (response.usage) {
          console.log(`Tokens used: ${response.usage.totalTokens}`);
        }
      }
    } catch (error) {
      console.error("Reasoning with efforts error:", error);
    }
  }

  // Example complex problem
  const problem = `
  A company has 3 departments. Department A has 15 employees with an average salary of $60,000. 
  Department B has 20 employees with an average salary of $75,000. 
  Department C has 10 employees with an average salary of $90,000.
  If the company wants to give everyone a 8% raise, but needs to keep the total payroll increase under $50,000, 
  what should they do?
  `;

  solveWithDifferentEfforts(problem);
  ```

  ```python Python theme={null}
  import os
  from sudo import Sudo

  def solve_with_different_efforts(problem):
      """Solve the same problem with different reasoning efforts"""
      
      efforts = ["low", "medium", "high"] # Effort levels to control reasoning depth
      
      with Sudo(
          server_url="https://sudoapp.dev/api",
          api_key=os.getenv("SUDO_API_KEY"),
      ) as client:
          
          for effort in efforts:
              print(f"\n--- Reasoning Effort: {effort.upper()} ---")
              
              response = client.router.create(
                  model="o3",
                  messages=[
                      {"role": "user", "content": problem}
                  ],
                  reasoning_effort=effort
              )
              
              print(response.choices[0].message.content)
              
              # Show token usage for different efforts
              if response.usage:
                  print(f"Tokens used: {response.usage.total_tokens}")

  # Example complex problem
  problem = """
  A company has 3 departments. Department A has 15 employees with an average salary of $60,000. 
  Department B has 20 employees with an average salary of $75,000. 
  Department C has 10 employees with an average salary of $90,000.
  If the company wants to give everyone a 8% raise, but needs to keep the total payroll increase under $50,000, 
  what should they do?
  """

  solve_with_different_efforts(problem)
  ```
</CodeGroup>

## Next Steps

1. **[CRUD Operations](/sdk/sudo-sdk/crud-operations)** - Manage stored completions

<Tip>
  Reasoning models like o3 excel at complex problem-solving, mathematical reasoning, and multi-step analysis. Use higher reasoning effort levels for more complex problems, but be aware they consume more tokens. Both TypeScript and Python SDKs provide full support for reasoning capabilities with proper error handling.
</Tip>
