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

Công cụ

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

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

Trong bài viết này — các ví dụ mã 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ì: Khóa API JoinGonka (định dạng jg-xxx). Nhận miễn phí tại gate.joingonka.ai/register cùng với 10M token thưởng.

curl — yêu cầu từ terminal

Cách nhanh nhất để kiểm tra API — 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": "Qwen/Qwen3-235B-A22B-Instruct-2507-FP8",
    "messages": [
      {"role": "user", "content": "Gonka là gì?"}
    ]
  }'

Streaming (phản hồi theo 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": "Qwen/Qwen3-235B-A22B-Instruct-2507-FP8",
    "messages": [
      {"role": "user", "content": "Viết hello world bằng Python"}
    ],
    "stream": true
  }'

Phản hồi đến dưới 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:

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="Qwen/Qwen3-235B-A22B-Instruct-2507-FP8",
    messages=[
        {"role": "user", "content": "Giải thích blockchain bằng những từ đơn giản"}
    ],
)

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

Streaming:

stream = client.chat.completions.create(
    model="Qwen/Qwen3-235B-A22B-Instruct-2507-FP8",
    messages=[{"role": "user", "content": "Viết thuật toán sắp xếp bằng 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": "Nhận thời tiết ở một thành phố",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "Tên thành phố"}
            },
            "required": ["city"]
        }
    }
}]

response = client.chat.completions.create(
    model="Qwen/Qwen3-235B-A22B-Instruct-2507-FP8",
    messages=[{"role": "user", "content": "Thời tiết ở Moscow như thế nào?"}],
    tools=tools,
)

tool_call = response.choices[0].message.tool_calls[0]
print(f"Hàm: {tool_call.function.name}")
print(f"Đối số: {tool_call.function.arguments}")

Qwen3-235B hỗ trợ gọi công cụ gốc — các hàm được gọi chính xác, không cần phân tích cú pháp phản hồi văn bản.

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: 'Qwen/Qwen3-235B-A22B-Instruct-2507-FP8',
    messages: [
      { role: 'user', content: 'Viết máy chủ Express.js' },
    ],
  });

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

main();

Streaming:

const stream = await client.chat.completions.create({
  model: 'Qwen/Qwen3-235B-A22B-Instruct-2507-FP8',
  messages: [{ role: 'user', content: 'Giải thích 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: 'Qwen/Qwen3-235B-A22B-Instruct-2507-FP8',
  messages: [{ role: 'user', content: 'Chuyển đổi 100 USD thành EUR' }],
  tools: [{
    type: 'function',
    function: {
      name: 'convert_currency',
      description: 'Chuyển đổi tiền tệ',
      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(`Hàm: ${toolCall?.function.name}`);
console.log(`Đối số: ${toolCall?.function.arguments}`);

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

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

JoinGonka Gateway hỗ trợ tất cả các tham số tiêu chuẩn của OpenAI Chat Completions API:

Tham sốLoạiMô tả
modelstringMô hình: Qwen/Qwen3-235B-A22B-Instruct-2507-FP8
messagesarrayLịch sử tin nhắn (hệ thống, người dùng, trợ lý)
streambooleanTạo 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 phản hồi tối đa (tối đa: 2048, mặc định: 1024)
toolsarrayĐịnh nghĩa chức năng cho cuộc gọi công cụ
tool_choicestring/objectChiến lược gọi chức năng

Tham số mô hình Qwen3-235B: cửa sổ ngữ cảnh — 128K token, phản hồi tối đa — 2048 token. Thông số kỹ thuật đầy đủ: HuggingFace. Danh sách các mô hình có sẵn qua GET /v1/models.

Hai điểm cuối:

  • Đị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-khóa-của-bạn (OpenAI) hoặc x-api-key: jg-khóa-của-bạn (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 hoặc framework nào hỗ trợ OpenAI hoặc Anthropic API đều hoạt động với JoinGonka Gateway mà không cần sửa đổi. Claude Code kết nối qua định dạng Anthropic trực tiếp.

JoinGonka Gateway — API tương thích OpenAI + Anthropic với giá $0.001/1M token. curl, Python, TypeScript — 3 dòng mã. Streaming, tool calling, tất cả các tham số OpenAI + Anthropic API. Claude Code hoạt động trực tiếp qua /v1/messages. 10M 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 10M token miễn phí →