Bắt đầu sử dụng API

Hướng dẫn nhanh để bắt đầu sử dụng các AI services trong vài phút

Quick Start

Chỉ với 3 bước đơn giản, bạn có thể bắt đầu sử dụng API ngay lập tức:

1 Kiểm tra Services đang chạy

Truy cập trang chủ và kiểm tra phần "Real-time Service Status" để đảm bảo các services bạn cần đang online.

Xem Status

2 Chọn Service và đọc Documentation

Chọn service phù hợp với nhu cầu của bạn và đọc tài liệu API:

  • Medical Transcribe - Chuyển âm thanh y tế sang văn bản
  • Face Recognition - Nhận diện khuôn mặt
  • Vistral Vietnamese - Chat AI tiếng Việt
  • DeepSeek OCR - Trích xuất văn bản từ hình ảnh
  • Medical Patient Simulator - Mô phỏng bệnh nhân ảo
  • MCP Backend - API Gateway với OAuth 2.0

3 Gửi Request đầu tiên

Sử dụng code example trong documentation để gửi request thử nghiệm.

Installation

Cài đặt các thư viện cần thiết cho ngôn ngữ lập trình bạn sử dụng:

Python

pip install requests

JavaScript (Node.js)

npm install axios form-data

PHP

PHP có sẵn cURL, không cần cài đặt thêm. Đảm bảo extension curl được enable:

php -m | grep curl

First Request

Ví dụ request đầu tiên với Medical Transcribe API:

Python Example

📌 LƯU Ý: Services CẦN API token! Liên hệ admin hoặc xem Authentication Guide

import requests
import os

# ===== BƯỚC 0: LẤY API TOKEN =====
# QUAN TRỌNG: Hầu hết services CẦN token!
API_TOKEN = os.getenv('API_AI_TOKEN')
# Hoặc: API_TOKEN = "demo_token_12345_for_testing_only"

if not API_TOKEN:
    print("⚠️ Cảnh báo: Chưa set API_TOKEN! Một số services sẽ trả về 401.")
    print("👉 Liên hệ admin để lấy token hoặc xem: authentication.php")

# ===== BƯỚC 1: KIỂM TRA SERVICE HEALTH =====
# Health endpoint thường KHÔNG cần token
health_url = "https://pnt.badt.vn/medical_transcribe/health"
health_response = requests.get(health_url)
print(f"✅ Service status: {health_response.json()['status']}")

# ===== BƯỚC 2: TRANSCRIBE AUDIO VỚI TOKEN =====
transcribe_url = "https://pnt.badt.vn/medical_transcribe/transcribe"

# Token PHẢI đi kèm trong header
headers = {'Authorization': f'Bearer {API_TOKEN}'} if API_TOKEN else {}

with open("audio.wav", "rb") as f:
    files = {"audio_file": f}
    data = {"language": "vi", "task": "transcribe"}
    
    response = requests.post(
        transcribe_url, 
        headers=headers,  # ← Token ở đây!
        files=files, 
        data=data
    )
    
    if response.status_code == 401:
        print("❌ Error 401: Token không hợp lệ hoặc chưa cung cấp!")
        print("👉 Lấy token tại: admin/tokens.php")
    elif response.status_code == 403:
        print("❌ Error 403: Token hết hạn hoặc không có quyền!")
    elif response.status_code == 200:
        result = response.json()
        if result["success"]:
            print(f"✅ Transcription: {result['transcription']}")
            print(f"⏱️  Processing time: {result['processing_time']:.2f}s")
        else:
            print(f"⚠️ Error: {result['error']}")
    else:
        print(f"⚠️ HTTP {response.status_code}: {response.text}")

# Output với token hợp lệ:
# ✅ Service status: healthy
# ✅ Transcription: Bệnh nhân có triệu chứng đau đầu và sốt cao
# ⏱️  Processing time: 1.23s

cURL Example

⚠️ QUAN TRỌNG: Hầu hết các services CẦN API token! Xem Authentication Guide

# 1. Kiểm tra health (không cần token)
curl https://pnt.badt.vn/medical_transcribe/health

# 2. Set API token (Liên hệ admin để lấy token)
export API_TOKEN="your_api_token_here"

# 3. Transcribe audio VỚI TOKEN
curl -X POST "https://pnt.badt.vn/medical_transcribe/transcribe" \
  -H "Authorization: Bearer $API_TOKEN" \
  -F "audio_file=@audio.wav" \
  -F "language=vi" \
  -F "task=transcribe"

# Ví dụ với demo token (chỉ dùng testing):
curl -X POST "https://pnt.badt.vn/medical_transcribe/transcribe" \
  -H "Authorization: Bearer demo_token_12345_for_testing_only" \
  -F "audio_file=@audio.wav" \
  -F "language=vi" \
  -F "task=transcribe"

Checklist

Trước khi bắt đầu, đảm bảo:

  • ✅ Tất cả services cần thiết đang chạy (kiểm tra ở trang chủ)
  • ✅ Bạn đã cài đặt thư viện client phù hợp
  • ✅ Bạn có quyền truy cập vào server (localhost hoặc remote)
  • ✅ Firewall cho phép kết nối đến ports cần thiết
  • ✅ Đã đọc documentation của service bạn muốn sử dụng

Base URLs

Service Base URL FastAPI Docs
Medical Transcribe https://pnt.badt.vn/medical_transcribe docs
Face Recognition https://pnt.badt.vn/face_recognition docs
Vistral Vietnamese https://pnt.badt.vn/vistral docs
DeepSeek OCR http://localhost:8040 docs
Dashboard https://pnt.badt.vn/dashboard docs
Medical Patient Simulator https://pnt.badt.vn/virtualpatient docs
MCP Backend https://pnt.badt.vn/mcp docs

Troubleshooting

Các vấn đề thường gặp:

  • Connection refused - Service chưa start hoặc sai port
  • Timeout - Request quá lớn hoặc service quá tải
  • 400 Bad Request - Sai format request body
  • 500 Internal Error - Lỗi server, kiểm tra logs

Giải pháp: Kiểm tra service status ở trang chủ, xem logs tại /path/to/service/logs/

Next Steps

Medical Transcribe

Chi tiết API chuyển đổi âm thanh

Authentication

Tìm hiểu về OAuth 2.0

More Examples

Xem thêm code examples