Skip to content

Commit 31a41c3

Browse files
RoRoJfpagnyofrancnerda-codes
authored
fix(genapis): add reasoning models (#5636)
* fix(genapis): add reasoning models * Apply suggestions from code review Co-authored-by: fpagny <[email protected]> * Apply suggestions from code review Co-authored-by: Océane <[email protected]> Co-authored-by: Néda <[email protected]> --------- Co-authored-by: fpagny <[email protected]> Co-authored-by: Océane <[email protected]> Co-authored-by: Néda <[email protected]>
1 parent a548004 commit 31a41c3

File tree

2 files changed

+169
-0
lines changed

2 files changed

+169
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
title: How to query reasoning models
3+
description: Learn how to interact with powerful reasoning models using Scaleway's Generative APIs service.
4+
tags: generative-apis ai-data language-models chat-completions-api reasoning think
5+
dates:
6+
validation: 2025-10-07
7+
posted: 2025-10-07
8+
---
9+
import Requirements from '@macros/iam/requirements.mdx'
10+
11+
Scaleway's Generative APIs service allows users to interact with language models benefiting from additional reasoning capabilities.
12+
13+
A reasoning model is a language model that is capable of carrying out multiple inference steps and systematically verifying intermediate results before producing answers. You can specify how much effort it should put into reasoning via dedicated parameters, and access reasoning content in its outputs. Even with default parameters, such models are designed to perform better on reasoning tasks like maths and logic problems than non-reasoning language models.
14+
15+
Language models supporting the reasoning feature include `gpt-oss-120b`. See [Supported Models](/generative-apis/reference-content/supported-models/) for a full list.
16+
17+
You can interact with reasoning models in the following ways:
18+
19+
- Use the [playground](/generative-apis/how-to/query-language-models/#accessing-the-playground) in the Scaleway [console](https://console.scaleway.com) to test models, adapt parameters, and observe how your changes affect the output in real-time.
20+
- Use the [Chat Completions API](https://www.scaleway.com/en/developers/api/generative-apis/#path-chat-completions-create-a-chat-completion) or the [Responses API](https://www.scaleway.com/en/developers/api/generative-apis/#path-responses-beta-create-a-response)
21+
22+
<Requirements />
23+
24+
- A Scaleway account logged into the [console](https://console.scaleway.com)
25+
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
26+
- A valid [API key](/iam/how-to/create-api-keys/) for API authentication
27+
- Python 3.7+ installed on your system
28+
29+
## Querying reasoning language models via the playground
30+
31+
### Accessing the playground
32+
33+
Scaleway provides a web playground for instruct-based models hosted on Generative APIs.
34+
35+
1. Navigate to **Generative APIs** under the **AI** section of the [Scaleway console](https://console.scaleway.com/) side menu. The list of models you can query displays.
36+
2. Click the name of the chat model you want to try. Alternatively, click <Icon name="more" /> next to the chat model, and click **Try model** in the menu. Ensure that you choose a model with [reasoning capabilities](/generative-apis/reference-content/supported-models/).
37+
38+
The web playground displays.
39+
40+
### Using the playground
41+
42+
1. Enter a prompt at the bottom of the page, or use one of the suggested prompts in the conversation area.
43+
2. Edit the parameters listed on the right column, for example the default temperature for more or less randomness on the outputs.
44+
3. Switch models at the top of the page, to observe the capabilities of chat models offered via Generative APIs.
45+
4. Click **View code** to get code snippets configured according to your settings in the playground.
46+
47+
<Message type="note">
48+
You cannot currently set values for parameters such as `reasoning_effort`, or access reasoning metadata in the model's output, via the console playground. Query the models programmatically as shown below in order to access the full reasoning feature set.
49+
</Message>
50+
51+
## Querying reasoning language models via API
52+
53+
You can query models programmatically using your favorite tools or languages.
54+
In the example that follows, we will use the OpenAI Python client.
55+
56+
### Chat Completions API or Responses API?
57+
58+
Both the [Chat Completions API](/https://www.scaleway.com/en/developers/api/generative-apis/#path-chat-completions-create-a-chat-completion) and the [Responses API](https://www.scaleway.com/en/developers/api/generative-apis/#path-chat-completions-create-a-chat-completion) allow you to access and control reasoning for supported models. Scaleway's support of the Responses API is currently in beta.
59+
60+
Note however, that the Responses API was introduced in part to better support features for reasoning workflows, among other tasks. It provides richer support for reasoning than Chat Completions, for example, by providing chain-of-thought reasoning content in its responses.
61+
62+
For more information on Chat Completions versus Responses API, see the information provided in the [querying language models](/generative-apis/how-to/query-language-models/#chat-completions-api-or-responses-api) documentation.
63+
64+
### Installing the OpenAI SDK
65+
66+
Install the OpenAI SDK using pip:
67+
68+
```bash
69+
pip install openai
70+
```
71+
72+
### Initializing the client
73+
74+
Initialize the OpenAI client with your base URL and API key:
75+
76+
```python
77+
from openai import OpenAI
78+
79+
# Initialize the client with your base URL and API key
80+
client = OpenAI(
81+
base_url="https://api.scaleway.ai/v1", # Scaleway's Generative APIs service URL
82+
api_key="<SCW_SECRET_KEY>" # Your unique API secret key from Scaleway
83+
)
84+
```
85+
86+
### Generating a chat completion with reasoning
87+
88+
You can now create a chat completion with reasoning, using either the Chat Completions or Responses API, as shown in the following examples:
89+
90+
<Tabs id="generating-chat-completion">
91+
92+
<TabsTab label="Chat Completions API">
93+
94+
```python
95+
# Create a chat completion using the 'gpt-oss-120b' model
96+
response = client.chat.completions.create(
97+
model="gpt-oss-120b",
98+
messages=[{"role": "user", "content": "Describe a futuristic city with advanced technology and green energy solutions."}],
99+
temperature=0.2, # Adjusts creativity
100+
max_completion_tokens=512, # Limits the length of the output
101+
top_p=0.7, # Controls diversity through nucleus sampling. You usually only need to use temperature.
102+
reasoning_effort="medium"
103+
)
104+
105+
# Print the generated response
106+
print(f"Reasoning: {response.choices[0].message.reasoning_content}")
107+
print(f"Answer: {response.choices[0].message.content}")
108+
```
109+
110+
This code sends a message to the model, as well as specifying the effort to make with reasoning, and returns an answer based on your input. The model's reasoning metadata can be accessed as well as its answer, with outputs such as:
111+
112+
```python
113+
Reasoning: The user wants a description of a futuristic city with advanced tech and green energy solutions. Should be creative, vivid, detailed. No disallowed content. Provide description.
114+
115+
Answer: **City of Luminara – A Blueprint for the Future** <rest of answer truncated>
116+
```
117+
118+
</TabsTab>
119+
120+
<TabsTab label="Responses API (Beta)">
121+
122+
```python
123+
response = client.responses.create(
124+
model="gpt-oss-120b",
125+
input=[{"role": "user", "content": "Briefly describe a futuristic city with advanced technology and green energy solutions."}],
126+
temperature=0.2, # Adjusts creativity
127+
max_output_tokens=512, # Limits the length of the output
128+
top_p=0.7, # Controls diversity through nucleus sampling. You usually only need to use temperature.
129+
reasoning={"effort":"medium"}
130+
)
131+
# Print the generated response. Here, the last output message will contain the final content.
132+
# Previous outputs will contain reasoning content.
133+
for output in response.output:
134+
if output.type == "reasoning":
135+
print(f"Reasoning: {output.content[0].text}") # output.content[0].text can only be used with openai >= 1.100.0
136+
if output.type == "message":
137+
print(f"Answer: {output.content[0].text}")
138+
```
139+
This code sends a message to the model, as well as specifying the effort to make with reasoning, and returns an answer based on your input. The model's reasoning metadata can be accessed as well as its answer, with outputs such as:
140+
141+
```python
142+
Reasoning: The user asks: "Briefly describe a futuristic city with advanced technology and green energy solutions." They want a brief description. Should be concise but vivid. Provide details: architecture, transport, energy, AI, and sustainability. Probably a paragraph or a few sentences. Ensure it's brief. Let's produce a short description.
143+
144+
Answer: **Solaris Arcadia** rises from a reclaimed river delta, its skyline a lattice of translucent, self‑healing bioglass towers that
145+
```
146+
</TabsTab>
147+
</Tabs>
148+
149+
## Exceptions and legacy models
150+
151+
Some legacy models such as `deepseek-r1-distill-llama-70b` do not output reasoning data as described above, but make it available in the `content` field of the response inside special tags, as shown in the example below:
152+
153+
```
154+
response.content = "<think> The user asks for questions about mathematics (...) </think> Answer is 42."
155+
```
156+
157+
The reasoning content is inside the `<think>`...`</think>` tags, and you can parse the response accordingly to access such content. There is, however, a known bug that can lead the model to omit the opening `<think>` tag, so we suggest taking care when parsing such outputs.
158+
159+
Note that the `reasoning_effort` parameter is not available for this model.
160+
161+
162+
## Impact on token generation
163+
164+
Reasoning models generate reasoning tokens, which are billable. Generally these are in the model's output as part of the reasoning content. To limit the generation of reasoning tokens, you can adjust settings for the **reasoning effort** and **max completion/output tokens** parameters. Alternatively, use a non-reasoning model to avoid the generation of reasoning tokens and subsequent billing.
165+

pages/generative-apis/menu.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const generativeApisMenu = {
2222
label: 'Query language models',
2323
slug: 'query-language-models',
2424
},
25+
{
26+
label: "Query reasoning models",
27+
slug: "query-reasoning-models"
28+
},
2529
{
2630
label: 'Query vision models',
2731
slug: 'query-vision-models',

0 commit comments

Comments
 (0)