← all conversations

Disabling Reasoning in API

2025-02-222 turns3,612 charsgpt-4o
apireasoningmodel

Summary

The user wants to know if they can disable reasoning in reasoning models via API to compare them with non-reasoning models.

Messages

Can I disable <think> with reasoning models using API? Question | Help I want to test how reasoning models compare to non-reasoning models in certain tasks, but reasoning models without using their reasoning. Is there a way I can do API calls like this : import requests import json # Define the API endpoint and your API key api_url = "https://api.openai.com/v1/chat/completions" api_key = "your_api_key_here" # Define the prompt and the messages prompt = "Write a short poem about the stars." messages = [ {"role": "user", "content": prompt} ] # Set up the headers for the API request headers = { "Content-Type": "application/json", "Authorization": f"Bearer {api_key}" } # Set up the data for the API request data = { "model": "gpt-3.5-turbo", # Or "gpt-4" "messages": messages, "temperature": 0.7, # Adjust for creativity "max_tokens": 200 # Adjust for response length } # Make the API call response = requests.post(api_url, headers=headers, data=json.dumps(data)) # Check the response if response.status_code == 200: # Parse the JSON response result = response.json() # Print the AI's reply print(result['choices'][0]['message']['content']) else: # Print the error print(f"Error: {response.status_code}, {response.text}") But then I want the model to continue after an empty <think></think> section without thinking. Is this possible? Upvote 1 Downvote 0 Go to comments Share Share You could just edit out the <think></think> tag content with regular expression like this: Comment Cancel Image Show formatting options
No, you can't directly disable the `<think>` reasoning section in OpenAI's API models, as they do not explicitly expose internal thought processes in API calls. However, you can approximate this behavior in a few ways: ### Possible Workarounds: 1. **Remove Explicit Reasoning Prompts** Instead of asking the model to "think step by step" or "explain its reasoning," just provide direct instructions to generate an answer without explanation. 2. **Set `logprobs` to Focus on Output, Not Reasoning** While OpenAI’s current API does not expose `logprobs` for chat models, some models allow you to see token probabilities. You can filter out tokens that indicate reasoning. 3. **Use a Non-Reasoning Model** If you're comparing reasoning vs. non-reasoning, try models that lack explicit reasoning capabilities (e.g., smaller LLMs or instruction-tuned models that favor direct answers). 4. **Regex or Post-Processing to Remove `<think>` Sections** If your model outputs something like: ``` <think>Let’s first analyze the problem logically...</think> The answer is 42. ``` You can strip the `<think></think>` content before displaying or using the response. Example: ```python import re def remove_think_section(response_text): return re.sub(r"<think>.*?</think>", "", response_text, flags=re.DOTALL).strip() # Example usage ai_response = "<think>Let’s analyze the problem...</think> The answer is 42." print(remove_think_section(ai_response)) # Output: "The answer is 42." ``` 5. **Use System Prompts to Discourage Thinking Steps** ```python system_message = { "role": "system", "content": "Answer questions directly without explanation. Do not provide reasoning or step-by-step solutions." } messages.insert(0, system_message) ``` There’s no explicit API flag to disable `<think>`, but these approaches should help approximate the effect. Would you like to try this with a local LLM that gives you more control?
gpt-4o