Gemini 2.5 Flash Thinking Tokens using OpenAI API

Update: Here’s a minimal example that reproduces the behavior. It’s a little tricky to get it to consistently reason, but this looks to produce reasoning tokens about 30% of the time.

I can actually get it to produce the behavior without structured output; it’s just rarer (maybe 5% of requests).


url = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions"
api_key = 'XXXX'
msgs = [
    "If you remove every other letter from 'SUBSTANTIATION,' what's the resulting word?",
    "If yesterday's tomorrow is Friday, what day is two days before today's yesterday?",
    "How many unique ways can you arrange the letters in 'MISSISSIPPI'?",
    "Explain briefly why mirrors reverse left-to-right but not up-to-down.",
    "If all roses are flowers and some flowers fade quickly, must some roses fade quickly?",
    "Is it logically possible for an omnipotent being to create a rock it can't lift?",
    "Which weighs more: a pound of feathers on Earth or a pound of iron on the Moon?",
    "If all cats chase some mice and all mice fear all dogs, do all cats fear some dogs?",
    "Does the set of all sets that don't contain themselves contain itself?",
    "If two people each flip a fair coin five times, what's the probability their results match exactly?",
    "Explain in one sentence why multiplying two negative numbers yields a positive result.",
    "If there are three apples and you take two, how many apples do you have?",
    "Can a statement be both completely true and completely false simultaneously?",
    "If you always lie and you say 'I always lie,' are you lying or telling the truth?",
    "If today is Wednesday, what is the day 1000 days from now?",
    "Which is larger: 2^30 or 3^20?",
    "A triangle has angles in a 1:2:3 ratio; what are the three angle measurements?",
    "Can the average height of a population increase even if every individual's height decreases?",
    "Does adding salt to water increase or decrease its freezing point?",
    "Which has a greater perimeter: a square with an area of 16 or a rectangle with an area of 16 and dimensions 1 by 16?"
]

for msg in msgs:
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + api_key,
    }
    body = {
        "model": 'gemini-2.5-flash-preview-04-17',
        "reasoning_effort": "none",
        "messages": [
            {
                "role": "system",
                "content": 'You are a helpful assistant. '
                           'Answer the question using reasoning, with careful step-by-step reasoning before producing an answer.'
            },
            {
                "role": "user",
                "content": msg
            }
        ],
        "response_format": {
            "type": 'json_schema',
            "json_schema": {
                'name': 'result',
                'schema': {
                    'type': 'object',
                    'properties': {
                        'explanation': {
                            'type': 'string'
                        },
                        'answer': {
                            'type': 'string'
                        }
                    },
                    'required': ['explanation', 'answer'],
                }
            }
        }
    }
    r = requests.post(url, headers=headers, json=body)
    js = r.json()
    reasoning_tokens = (js['usage']['total_tokens'] -
                        js['usage']['prompt_tokens'] -
                        js['usage']['completion_tokens'])
    print(reasoning_tokens)