Python

Python client

Проверенный способ — официальный пакет openai с canonical 42gpu base URL.

Репозиторный legacy SDK пока не соответствует canonical contract и не документируется как поддерживаемый пакет 42gpu. Не используйте примеры pip install gpu42 или from gpu42 import GPU42.

Установка

Terminal
python -m pip install openai

Обычный запрос

chat.py
1import os
2from openai import OpenAI
3
4client = OpenAI(
5 base_url="https://api.42gpu.ru/vllm/v1",
6 api_key=os.environ["GPU42_API_KEY"],
7 timeout=900.0,
8)
9
10response = 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)
16
17print(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)
8
9for chunk in stream:
10 if not chunk.choices:
11 if chunk.usage:
12 print("\nusage:", chunk.usage)
13 continue
14 delta = chunk.choices[0].delta
15 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)
10
11message = response.choices[0].message
12print(getattr(message, "reasoning_content", None))
13print(message.content)
Поддерживается OpenAI-style Chat Completions wire format только в границах этой документации. Account/billing методы не являются частью OpenAI client и используют dashboard JWT. См. точный parameter contract.