Python
Python client
Проверенный способ — официальный пакет openai с canonical 42gpu base URL.
pip install gpu42 или from gpu42 import GPU42.Установка
Terminal
python -m pip install openaiОбычный запрос
chat.py
1import os2from openai import OpenAI34client = OpenAI(5 base_url="https://api.42gpu.ru/vllm/v1",6 api_key=os.environ["GPU42_API_KEY"],7 timeout=900.0,8)910response = client.chat.completions.create(11 model="Qwen/Qwen3.5-397B-A17B-FP8",12 messages=[{"role": "user", "content": "Привет!"}],13 max_tokens=512,14 extra_body={"chat_template_kwargs": {"enable_thinking": False}},15)1617print(response.choices[0].message.content)18print(response.usage)Streaming
stream.py
1stream = client.chat.completions.create(2 model="Qwen/Qwen3.5-397B-A17B-FP8",3 messages=[{"role": "user", "content": "Объясни фотосинтез"}],4 stream=True,5 stream_options={"include_usage": True},6 max_tokens=1024,7)89for chunk in stream:10 if not chunk.choices:11 if chunk.usage:12 print("\nusage:", chunk.usage)13 continue14 delta = chunk.choices[0].delta15 reasoning = getattr(delta, "reasoning_content", None)16 if reasoning:17 print(reasoning, end="", flush=True)18 if delta.content:19 print(delta.content, end="", flush=True)Reasoning fields
reasoning_content — расширение response shape. В зависимости от версии client оно доступно как attribute или в raw model data.
reasoning.py
1response = client.chat.completions.create(2 model="Qwen/Qwen3.5-397B-A17B-FP8",3 messages=[{"role": "user", "content": "Реши 17 × 24"}],4 max_tokens=2048,5 extra_body={6 "chat_template_kwargs": {"enable_thinking": True},7 "thinking_token_budget": 1024,8 },9)1011message = response.choices[0].message12print(getattr(message, "reasoning_content", None))13print(message.content)