OpenAI SDK

Использование официального OpenAI SDK со шлюзом в качестве baseURL без изменения API.

Интеграции

Официальный пакет openai для TypeScript и Python работает без модификаций. Укажите адрес шлюза в baseURL или base_url, передайте ключ gw_ — и можно отправлять запросы. Потоковые и обычные ответы, function calling и embeddings (для поддерживающих их моделей) проходят через шлюз.

TypeScript

ts
import OpenAI from "openai";const client = new OpenAI({apiKey: process.env.GATEWAY_KEY,baseURL: "https://api.toygate.store/v1",});const response = await client.chat.completions.create({model: "gpt-5.5",messages: [{ role: "user", content: "Say hi" }],});console.log(response.choices[0]?.message?.content);

Потоковый вариант:

const stream = await client.chat.completions.create({
  model: "gpt-5.5",
  stream: true,
  messages: [{ role: "user", content: "Stream me a sentence." }],
});

for await (const chunk of stream) {
  const delta = chunk.choices[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}

Python

python
from openai import OpenAIclient = OpenAI(  api_key=os.environ["GATEWAY_KEY"],  base_url="https://api.toygate.store/v1",)response = client.chat.completions.create(  model="gpt-5.5",  messages=[{"role": "user", "content": "Say hi"}],)print(response.choices[0].message.content)

Function calling

Вызовы функций проходят по всей цепочке: шлюз переводит определения инструментов OpenAI в формат upstream, а ответы tool_use — обратно в tool_calls. Модель должна поддерживать инструменты: в каталоге у неё должно быть capabilities.tools = true.

const response = await client.chat.completions.create({
  model: "gpt-5.5",
  messages: [{ role: "user", content: "What time is it in Tokyo?" }],
  tools: [
    {
      type: "function",
      function: {
        name: "current_time",
        description: "Returns the current local time in the given timezone.",
        parameters: {
          type: "object",
          properties: { timezone: { type: "string" } },
          required: ["timezone"],
        },
      },
    },
  ],
});

Поддерживаемые возможности

Возможность OpenAIСтатус
chat.completions.create (sync)✅
chat.completions.create (stream)✅
Вызовы инструментов✅ при capabilities.tools = true
Vision (части image_url)✅ передаются для vision-моделей; иначе 400 model_does_not_support_images
Structured output (response_format)❌ 400 response_format_not_supported
Embeddings➖ зависит от конфигурации оператора
Assistants API❌ не реализован
Realtime API❌ не реализован

URL шлюза: https://api.toygate.store