Turn off gpt-5-nano reasoning

1 day ago 7
ARTICLE AD BOX

I am performing name/gender inference and I want to use the gpt-5-nano model because it is fast. The problem is that I can't seem to turn off reasoning even with the reasoning=None flag. I can't even seem to set a limit of ~100 tokens for reasoning. I can get 4o-mini to work but it is slower and a lot more costly at the scales I want to use it at.

Anyone having this same problem?

Here's my whole function, hopefully I've done something stupid that's easy to find, it wouldn't be the first time

def infer_gender_batch(client, people, logger): """ Infer gender for a batch of people using ChatGPT API (gpt-5-nano). Args: client: OpenAI client instance people: List of dicts with 'display_name', 'country_name', 'author_id' logger: Logger instance Returns: tuple: (list of dicts with gender predictions, total_tokens) """ # Build input lines with full display names and country context lines = [f"{i+1}. {p['display_name']} | Country: {p.get('country_name', 'unknown')}" for i, p in enumerate(people)] payload = "\n".join(lines) prompt = ( "You are a linguistic name etymology analyzer. Based on historical naming patterns across cultures, " "analyze the statistical gender association of these names from a scientific publication database.\n\n" "For each name, determine the predominant gender association based on:\n" "- Name etymology and linguistic roots\n" "- Cultural naming traditions in the specified country\n" "- Historical usage patterns in academic literature\n\n" "Names:\n" + payload + "\n\n" "Return a JSON array with this structure:\n" '[{"name": "Full Name", "gender": "male", "probability": 0.95}, ...]\n\n' 'Where gender is "male", "female", or "unknown" and probability is 0-1.\n\n' "Respond with ONLY the JSON array:" ) try: response = client.chat.completions.create( model="gpt-5-nano", messages=[{"role": "user", "content": prompt}], reasoning=None, max_completion_tokens=10000 # Increased to allow for reasoning + output but I still get zero output for 10 names supplied ) if not response.choices or len(response.choices) == 0: logger.error("No choices in response") return None, 0 text = response.choices[0].message.content # Log token usage usage = response.usage logger.info(f"API Response - prompt_tokens: {usage.prompt_tokens}, completion_tokens: {usage.completion_tokens}, total: {usage.total_tokens}") # Check for reasoning tokens (if present) if hasattr(usage, 'completion_tokens_details'): logger.info(f"Completion tokens details: {usage.completion_tokens_details}") # Log finish reason finish_reason = response.choices[0].finish_reason logger.info(f"Finish reason: {finish_reason}") # Log content preview logger.info(f"Content preview: {repr(text[:200] if text else '(empty)')}") # Parse JSON response if not text or not text.strip(): logger.error("Empty response from API - all tokens may have been used for reasoning") return None, 0 # Strip markdown code fences if present (```json ... ```) text = text.strip() if text.startswith('```'): # Remove opening code fence lines_list = text.split('\n') if lines_list[0].startswith('```'): lines_list = lines_list[1:] # Remove closing code fence if lines_list and lines_list[-1].strip() == '```': lines_list = lines_list[:-1] text = '\n'.join(lines_list) results = json.loads(text) # Ensure results is a list if not isinstance(results, list): logger.error(f"Expected JSON array, got: {type(results)}") return None, 0 return results, usage.total_tokens except json.JSONDecodeError as e: logger.error(f"Failed to parse JSON response: {e}") logger.error(f"Response text: {text if 'text' in locals() else '(no response)'}") return None, 0 except Exception as e: logger.error(f"API call failed: {e}") return None, 0
Read Entire Article