Các phần cơ sở kiến thức ▾

Điều hướng

▸ Bắt đầu tại đây Theo vai trò

Danh mục

Công cụ 52
Bảng thuật ngữ 12

Công cụ

Khởi động nhanh API — curl, Python, TypeScript

JoinGonka Gateway cung cấp API tương thích với OpenAI + Anthropic cho mạng lưới phi tập trung Gonka. Bất kỳ mã nguồn nào được viết cho OpenAI API (/v1/chat/completions) đều hoạt động với Gonka — chỉ cần thay đổi base_url và api_key. Ngoài ra, các công cụ trên Anthropic API (Claude Code) kết nối thông qua /v1/messages — trực tiếp, không cần proxy.

Trong bài viết này, chúng tôi cung cấp các ví dụ mã nguồn sẵn sàng cho ba công cụ phổ biến nhất: curl (dòng lệnh), Python và TypeScript/Node.js (định dạng OpenAI). Đối với định dạng Anthropic, xem hướng dẫn Claude Code.

Bạn cần gì: API-key JoinGonka (định dạng jg-xxx). Nhận miễn phí tại gate.joingonka.ai/register cùng với phần thưởng 3M token.

curl — yêu cầu từ terminal

Cách nhanh nhất để kiểm tra API là dùng curl:

Yêu cầu thông thường:

curl https://gate.joingonka.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer jg-your-key" \
  -d '{
    "model": "MiniMaxAI/MiniMax-M2.7",
    "messages": [
      {"role": "user", "content": "What is Gonka?"}
    ]
  }'

Streaming (phản hồi từng phần):

curl https://gate.joingonka.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer jg-your-key" \
  -d '{
    "model": "MiniMaxAI/MiniMax-M2.7",
    "messages": [
      {"role": "user", "content": "Write hello world in Python"}
    ],
    "stream": true
  }'

Phản hồi trả về ở định dạng JSON (thông thường) hoặc Server-Sent Events (streaming) — hoàn toàn tương thích với OpenAI API.

Python — openai SDK

OpenAI Python SDK chính thức hoạt động với JoinGonka Gateway mà không cần thay đổi gì:

pip install openai

Yêu cầu thông thường:

from openai import OpenAI

client = OpenAI(
    base_url="https://gate.joingonka.ai/v1",
    api_key="jg-your-key",
)

response = client.chat.completions.create(
    model="MiniMaxAI/MiniMax-M2.7",
    messages=[
        {"role": "user", "content": "Explain blockchain in simple terms"}
    ],
)

print(response.choices[0].message.content)

Streaming:

stream = client.chat.completions.create(
    model="MiniMaxAI/MiniMax-M2.7",
    messages=[{"role": "user", "content": "Write a sorting function in Python"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Tool calling:

import json

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the weather in a city",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "City name"}
            },
            "required": ["city"]
        }
    }
}]

response = client.chat.completions.create(
    model="MiniMaxAI/MiniMax-M2.7",
    messages=[{"role": "user", "content": "What is the weather in Moscow?"}],
    tools=tools,
)

tool_call = response.choices[0].message.tool_calls[0]
print(f"Function: {tool_call.function.name}")
print(f"Arguments: {tool_call.function.arguments}")

Các mô hình trong mạng hỗ trợ native tool calling — các hàm được gọi chính xác, không cần phân tích cú pháp văn bản phản hồi.

TypeScript/Node.js — openai SDK

Cài đặt:

npm install openai

Yêu cầu thông thường:

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://gate.joingonka.ai/v1',
  apiKey: 'jg-your-key',
});

async function main() {
  const response = await client.chat.completions.create({
    model: 'MiniMaxAI/MiniMax-M2.7',
    messages: [
      { role: 'user', content: 'Write an Express.js server' },
    ],
  });

  console.log(response.choices[0].message.content);
}

main();

Streaming:

const stream = await client.chat.completions.create({
  model: 'MiniMaxAI/MiniMax-M2.7',
  messages: [{ role: 'user', content: 'Explain async/await' }],
  stream: true,
});

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

Tool calling:

const response = await client.chat.completions.create({
  model: 'MiniMaxAI/MiniMax-M2.7',
  messages: [{ role: 'user', content: 'Convert 100 USD to EUR' }],
  tools: [{
    type: 'function',
    function: {
      name: 'convert_currency',
      description: 'Currency conversion',
      parameters: {
        type: 'object',
        properties: {
          amount: { type: 'number' },
          from: { type: 'string' },
          to: { type: 'string' },
        },
        required: ['amount', 'from', 'to'],
      },
    },
  }],
});

const toolCall = response.choices[0].message.tool_calls?.[0];
console.log(`Function: ${toolCall?.function.name}`);
console.log(`Arguments: ${toolCall?.function.arguments}`);

Tất cả các ví dụ đều dùng OpenAI SDK chính thức — không cần thư viện bổ sung nào. Chỉ cần thay thế base_url và api_key.

Các tham số API được hỗ trợ

JoinGonka Gateway hỗ trợ toàn bộ tham số tiêu chuẩn của OpenAI Chat Completions API:

Tham sốKiểuMô tả
modelstringMô hình: MiniMaxAI/MiniMax-M2.7
messagesarrayLịch sử tin nhắn (system, user, assistant)
streambooleanTạo phản hồi dạng luồng (SSE). Mặc định: false
temperaturenumberĐộ sáng tạo của phản hồi (0.0 — 2.0)
max_tokensintegerĐộ dài tối đa của phản hồi (tối đa: 8192, với DeepSeek V4 Flash — 32768; mặc định khi không có max_tokens — 1500)
toolsarrayĐịnh nghĩa hàm cho tool calling
tool_choicestring/objectChiến lược gọi hàm

Tham số của các mô hình trong mạng: cửa sổ ngữ cảnh — 200K token với MiniMax M2.7 (380K với DeepSeek V4 Flash, 390K với GLM-5.3 Flash), phản hồi tối đa — lên đến 8192 token (với DeepSeek V4 Flash — lên đến 32768). Danh sách mô hình có thể truy cập qua GET /v1/models.

Hai endpoint:

  • Định dạng OpenAI: POST https://gate.joingonka.ai/v1/chat/completions
  • Định dạng Anthropic: POST https://gate.joingonka.ai/v1/messages

Xác thực: Authorization: Bearer jg-your-key (OpenAI) hoặc x-api-key: jg-your-key (Anthropic)

Định dạng phản hồi hoàn toàn tương thích với OpenAI và Anthropic — bất kỳ SDK, thư viện hay framework nào hỗ trợ OpenAI hoặc Anthropic API đều hoạt động với JoinGonka Gateway mà không cần chỉnh sửa. Claude Code kết nối trực tiếp qua định dạng Anthropic.

JoinGonka Gateway — API tương thích với OpenAI + Anthropic với giá $0.0069/1M token. curl, Python, TypeScript — 3 dòng mã. Streaming, tool calling, tất cả các tham số của OpenAI + Anthropic API. Claude Code hoạt động trực tiếp qua /v1/messages. 3M token miễn phí khi bắt đầu.

Muốn tìm hiểu thêm?

Khám phá các phần khác hoặc bắt đầu kiếm GNK ngay bây giờ.

Nhận token miễn phí →