These tokens offer insight into the model’s reasoning process, providing a transparent view of its thought steps. Since Reasoning Tokens are considered output tokens, they are billed accordingly.

To access Reasoning Tokens when available, include include_reasoning: true in your API request. The tokens will be returned in the reasoning field of each message.

While all reasoning-enabled models generate these tokens, only certain models and providers include them in the response.

Reasoning code example

import OpenAI from 'openai';

// Configure OpenAI with custom base URL
const client = new OpenAI({
    baseURL: 'https:/router.requesty.ai/v1',
    apiKey: 'api_key'
});

async function testReasoningModel() {
    try {
        const prompt = `
            Write a bash script that takes a matrix represented as a string with
            format '[1,2],[3,4],[5,6]' and prints the transpose in the same format.
        `.trim();

        console.log('Sending request to local reasoning model...');

        const completion = await client.chat.completions.create({
            model: "openai/o3-mini",
            reasoning_effort: "medium",
            messages: [
                {
                    role: "user",
                    content: prompt
                }
            ],
            store: true
        });

        // Log the completion details
        console.log('\nCompletion Response:');
        console.log('-------------------');
        if (completion.choices[0]?.message?.content) {
            console.log(completion.choices[0].message.content);
        }

        // Log token usage details
        console.log('\nToken Usage Details:');
        console.log('-------------------');
        if (completion.usage) {
            const usageDetails = {
                prompt_tokens: completion.usage.prompt_tokens,
                completion_tokens: completion.usage.completion_tokens,
                total_tokens: completion.usage.total_tokens
            };
            console.log(JSON.stringify(usageDetails, null, 2));

            // Log specific reasoning token details if available
            if ('completion_tokens_details' in completion.usage) {
                console.log('\nReasoning Token Details:');
                console.log('----------------------');
                console.log(JSON.stringify(completion.usage.completion_tokens_details, null, 2));
            }
        }

    } catch (error) {
        console.error('Error testing reasoning model:');
        if (error instanceof Error) {
            console.error('Error:', error.message);
        }
    }
}

// Run the test
testReasoningModel();