AI Content Writer API

RESTful API để tạo nội dung tự động bằng AI. Tích hợp OpenAI GPT và Google Search để tạo ra những bài viết chất lượng cao.

API Online Version 1.0.0 Updated 2024-06-02

Tổng quan

Tính năng chính
  • Đăng ký/đăng nhập với JWT
  • Google OAuth integration
  • Tìm kiếm Google tự động
  • Tạo outline bằng AI
  • Viết nội dung bằng OpenAI
  • Quản lý cài đặt cá nhân
Thông tin kỹ thuật
  • Base URL: https://dlpanda.net
  • API Version: 1.0.0
  • Content Type: application/json
  • Charset: UTF-8
  • Rate Limit: 100 req/hour

Xác thực

API sử dụng JWT (JSON Web Token) để xác thực. Sau khi đăng nhập, bạn sẽ nhận được token để sử dụng cho các request khác.

Cách sử dụng Token
Authorization: Bearer YOUR_JWT_TOKEN_HERE
Token có thời hạn 7 ngày. Hệ thống sẽ tự động refresh token khi gần hết hạn.

Authentication API

POST /api/auth/register

Đăng ký tài khoản mới

{
  "name": "Nguyễn Văn A",
  "email": "[email protected]",
  "password": "password123",
  "confirm_password": "password123"
}
POST /api/auth/login

Đăng nhập vào hệ thống

{
  "email": "[email protected]",
  "password": "password123"
}
POST /api/auth/google-login

Đăng nhập bằng Google OAuth

{
  "token": "google_id_token_here"
}
GET /api/auth/profile

Lấy thông tin profile người dùng

Requires: Authorization header

Content Management API

POST /api/content/create-article

Tạo bài viết mới

{
  "keyword": "cách làm bánh cupcake",
  "language": "vi",
  "tone": "friendly",
  "content_suggestion": "Bổ sung thông tin về nguyên liệu..."
}
POST /api/content/search

Tìm kiếm thông tin trên Google

{
  "keyword": "cách làm bánh cupcake",
  "article_id": "123",
  "num_results": 10
}
POST /api/content/generate-outline

Tạo outline bằng AI

{
  "keyword": "cách làm bánh cupcake",
  "language": "vi",
  "tone": "friendly",
  "content_suggestion": "...",
  "article_id": "123"
}
POST /api/content/generate-content

Tạo nội dung bằng AI

{
  "article_id": "123",
  "keyword": "cách làm bánh cupcake",
  "language": "vi",
  "tone": "friendly",
  "outline": "I. Giới thiệu...",
  "content_suggestion": "..."
}
GET /api/content/articles?limit=10&offset=0

Lấy danh sách bài viết

Settings API

GET /api/settings

Lấy cài đặt người dùng

PUT /api/settings/api-keys

Cập nhật API keys

{
  "openai_api_key": "sk-...",
  "google_search_api_key": "AIza...",
  "google_cse_id": "017..."
}
PUT /api/settings/prompts

Cập nhật prompts tùy chỉnh

{
  "outline_prompt": "Custom outline prompt...",
  "content_prompt": "Custom content prompt..."
}

HTTP Status Codes

Code Status Mô tả
200 OK Request thành công
201 Created Tạo mới thành công
400 Bad Request Request không hợp lệ
401 Unauthorized Chưa xác thực
403 Forbidden Không có quyền truy cập
404 Not Found Không tìm thấy resource
422 Validation Error Dữ liệu không hợp lệ
429 Rate Limit Vượt quá giới hạn request
500 Server Error Lỗi máy chủ

Ví dụ sử dụng

JavaScript (Fetch API)
// Đăng nhập
const loginResponse = await fetch('https://dlpanda.net/api/auth/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: '[email protected]',
    password: 'password123'
  })
});

const loginData = await loginResponse.json();
const token = loginData.data.token;

// Tạo bài viết
const createResponse = await fetch('https://dlpanda.net/api/content/create-article', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${token}`
  },
  body: JSON.stringify({
    keyword: 'cách làm bánh cupcake',
    language: 'vi',
    tone: 'friendly'
  })
});

const articleData = await createResponse.json();
Python (Requests)
import requests

# Đăng nhập
login_response = requests.post('https://dlpanda.net/api/auth/login', json={
    'email': '[email protected]',
    'password': 'password123'
})

token = login_response.json()['data']['token']

# Tạo bài viết
headers = {
    'Authorization': f'Bearer {token}',
    'Content-Type': 'application/json'
}

article_response = requests.post('https://dlpanda.net/api/content/create-article', 
    headers=headers,
    json={
        'keyword': 'cách làm bánh cupcake',
        'language': 'vi',
        'tone': 'friendly'
    }
)
cURL
# Đăng nhập
curl -X POST https://dlpanda.net/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","password":"password123"}'

# Tạo bài viết (với token)
curl -X POST https://dlpanda.net/api/content/create-article \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -d '{"keyword":"cách làm bánh cupcake","language":"vi","tone":"friendly"}'