Tài liệu dành cho nhà phát triển

Xây dựng với API Wordly.

Sử dụng khóa API phía máy chủ, thực hiện các yêu cầu HTTPS và theo dõi mọi cuộc gọi thông qua mô hình thanh toán dựa trên tín dụng có thể dự đoán được. Tài liệu tham khảo này ghi lại các điểm cuối hiện có sẵn trong sản xuất và đánh dấu rõ ràng các điểm cuối vẫn đang được chuẩn bị.

API version v1định dạng JSONVận chuyển Chỉ HTTPSSố dư miễn phí 50 creditsAPI mở Tải xuống lược đồPostman CollectionPostman Environment

Bắt đầu nhanh

Tạo một tài khoản miễn phí, xác minh email của bạn bằng mã gồm sáu chữ số và sao chép khóa API được hiển thị một lần trong trang tổng quan dành cho nhà phát triển của bạn.

  1. 1
    Tạo một tài khoản

    Đăng ký chỉ với một địa chỉ email và mật khẩu.

  2. 2
    Xác minh email của bạn

    Nhập mã được gửi bởi [email protected]. Verification grants 50 free credits.

  3. 3
    Lưu trữ khóa API của bạn

    Sao chép được tạo wly_live_... key và giữ nó trong biến môi trường phía máy chủ.

  4. 4
    Đưa ra yêu cầu kiểm tra

    Gọi tới điểm cuối tài khoản để xác minh xác thực và xem số dư còn lại.

Vỏ
curl "https://api.wordlyenglish.com/v1/account" \
  -H "Authorization: Bearer $WORDLY_API_KEY" \
  -H "Accept: application/json"
200 response
{
  "data": {
    "message": "Authenticated",
    "credits_remaining": 50
  },
  "meta": { "lang": "en" }
}

URL cơ sở và phiên bản

Tất cả các điểm cuối sản xuất đều được phân phối từ URL cơ sở được phiên bản sau:

URL cơ sởhttps://api.wordlyenglish.com/v1

Các thay đổi về phản hồi hoặc hành vi sẽ sử dụng phiên bản đường dẫn mới. Các trường bổ sung có thể được giới thiệu trong v1, so clients should ignore response properties they do not recognize.

Xác thực

Điểm cuối được xác thực yêu cầu khóa API trong HTTP Authorization tiêu đề bằng cách sử dụng lược đồ Bearer.

Authorization: Bearer wly_live_your_api_key
Không để lộ khóa API.

Không bao giờ đặt khóa trực tiếp trong JavaScript của trình duyệt, kho lưu trữ Git công khai, ảnh chụp màn hình, nhật ký hoặc ứng dụng di động được phân phối. Gọi API Wordly từ chương trình phụ trợ của bạn và để ứng dụng của riêng bạn giao tiếp với chương trình phụ trợ đó.

Thông báo API được bản địa hóa

Đặt ngôn ngữ phản hồi với ?lang=tr hoặc tiêu chuẩn Accept-Language tiêu đề. Các tham số truy vấn được ưu tiên. Mọi phản hồi JSON đều khai báo ngôn ngữ đã chọn trong Content-Language và meta.lang. Error codes remain stable in English for programmatic handling; only the human-readable message is localized.

curl "https://api.wordlyenglish.com/v1/account?lang=tr" \
  -H "Authorization: Bearer $WORDLY_API_KEY" \
  -H "Accept-Language: tr-TR"

Mã ngôn ngữ được hỗ trợ: en, tr, de, fr, es, it, pt, nl, pl, ru, uk, ar, fa, he, hi, bn, ur, zh, ja, ko, id, ms, vi, th, sv, no, da, fi, cs, ro.

Tín dụng và thanh toán

Each successful metered request consumes the documented number of credits. Email-verified accounts receive 50 free credits once. Credits are deducted atomically, so concurrent requests cannot spend the same balance twice. Balance lookup through GET /v1/account is free.

hoạt độngChi phí tín dụngsẵn có
GET /v1/status0Trực tiếp
GET /v1/account0Trực tiếp
GET /v1/words/{word}1–5Trực tiếp
GET /v1/words/search1Trực tiếp
GET /v1/words/random1 per wordTrực tiếp
POST /v1/words/batchCăn cứ vào hồ sơ trả vềTrực tiếp

Use GET /v1/account when you need the current balance. Other endpoint responses include the operation charge but omit the remaining balance. When the balance is insufficient, the API returns HTTP 402 và không xử lý hoạt động.

402 response
{
  "error": {
    "code": "credits_exhausted",
    "message": "Your credit balance is exhausted. Add a package or enable pay-as-you-go to continue.",
    "upgrade_url": "/app.php?page=billing"
  }
}

API key lifecycle

Tạo các khóa riêng biệt để phát triển, dàn dựng và sản xuất. Wordly chỉ lưu trữ hàm băm mật mã của mỗi khóa; giá trị hoàn chỉnh được hiển thị một lần khi tạo.

  • Đặt tên cho các khóa theo môi trường hoặc dịch vụ.
  • Sử dụng các biến môi trường hoặc một kho lưu trữ bí mật được quản lý.
  • Thu hồi chìa khóa ngay lập tức nếu nó có thể bị lộ.
  • Xoay phím mà không sử dụng lại giá trị cũ.
  • Không gửi khóa trong chuỗi truy vấn.

Định dạng phản hồi

Phản hồi thành công sử dụng cấp cao nhất data đối tượng và có thể bao gồm một meta đối tượng. Lỗi luôn sử dụng mức cao nhất error đối tượng có thể đọc được bằng máy ổn định code và con người có thể đọc được message.

Yêu cầu thành công
{
  "data": { ... },
  "meta": {
    "credits_used": 1,
    "request_id": "..."
  }
}
Yêu cầu không thành công
{
  "error": {
    "code": "invalid_api_key",
    "message": "..."
  }
}

Giữ request_id khi liên hệ với bộ phận hỗ trợ về yêu cầu thanh toán thành công. JSON được mã hóa UTF-8 và khách hàng nên gửi Accept: application/json.

Cache behavior

Wordly caches shared vocabulary data on the server, never API keys, account identities, balances, rate-limit state, or request identifiers. Public status and language responses advertise shared-cache lifetimes. Authenticated responses remain private, no-store; applications may cache the stable data value in their own trusted backend when appropriate.

Tham chiếu điểm cuối

Điểm cuối sản xuất

NHẬN/v1/statusTrực tiếp

Trả về thông tin phiên bản API và trạng thái dịch vụ công cộng. Điểm cuối này không yêu cầu xác thực và không tốn tín dụng.

Yêu cầu mẫu

curl "https://api.wordlyenglish.com/v1/status" \
  -H "Accept: application/json"

200 · Success

{
  "data": { "status": "ok", "version": "v1" },
  "meta": { "lang": "en" }
}
Possible results200 Service is reachable.405 Method is not GET.429 IP request limit exceeded.
NHẬN/v1/accountLive · 0 credits

Validates the supplied key and returns the current account balance without charging a credit.

Tiêu đề

TênBắt buộcMô tả
AuthorizationCóBearer wly_live_...
AcceptĐược đề xuấtapplication/json

Tiêu đề phản hồi

X-Credits-Remaining is returned only by this balance endpoint.

200 · Success

{
  "data": { "message": "Authenticated", "credits_remaining": 1250 },
  "meta": { "lang": "en" }
}
Possible results200 Key accepted and balance returned.401 Missing, invalid, revoked, or suspended key.429 Rate limit exceeded.

Điểm cuối từ vựng

20,000+ catalog entries are live.

Mọi hồ sơ đều báo cáo completeness như catalog, translated, or enriched. Fields that are not available are returned as null hoặc một đối tượng trống rỗng thay vì dữ liệu được phát minh.

GET /v1/words/{word}

Trả về một từ khớp chính xác. sử dụng languages=tr,de,fr chỉ trả lại các bản dịch được yêu cầu. Danh mục hoặc bản dịch có giá 1 tín chỉ; hồ sơ được làm giàu đầy đủ có giá 5 tín chỉ.

curl "https://api.wordlyenglish.com/v1/words/water?languages=tr,de" \
  -H "Authorization: Bearer $WORDLY_API_KEY"

GET /v1/words/search

Tìm kiếm với q và tùy chọn level, part_of_speech, category, limit, and cursor. Limits range from 1 to 50. Pass meta.next_cursor vào yêu cầu tiếp theo.

curl "https://api.wordlyenglish.com/v1/words/search?q=app&level=advanced&limit=20" \
  -H "Authorization: Bearer $WORDLY_API_KEY"

GET /v1/words/random

Trả về 1–20 từ ngẫu nhiên. Lọc theo level, part_of_speech, or category. Each returned slot costs one credit.

POST /v1/words/batch

Tra cứu từ 1 đến 50 từ duy nhất trong một yêu cầu. Phản hồi duy trì thứ tự yêu cầu và đánh dấu mọi mục bằng found.

curl -X POST "https://api.wordlyenglish.com/v1/words/batch?lang=tr" \
  -H "Authorization: Bearer $WORDLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"words":["water","opportunity"],"languages":["tr","de"]}'

GET /v1/languages

Trả về tất cả 30 ngôn ngữ giao diện và thông báo API được hỗ trợ. Bản dịch từ vựng chỉ được trả lại khi có sẵn. Điểm cuối này là công khai và không tốn tín dụng.

Giới hạn tỷ lệ

Mỗi khóa API được giới hạn ở 120 yêu cầu được chấp nhận mỗi phút. Phản hồi bao gồm X-RateLimit-Limit và X-RateLimit-Remaining. A 429 rate_limit_exceeded phản ứng bao gồm Retry-After: 60.

NHẬN/v1/languagesLive · 0 credits

Lists all supported interface and API-message locales. Vocabulary translations are returned only when a record contains them.

Query parameters

TênTypeBắt buộcRulesMô tả
langstringNoSupported locale codeLanguage for human-readable messages.

Yêu cầu mẫu

curl "https://api.wordlyenglish.com/v1/languages?lang=tr"

200 · Success

{
  "data": [{
    "code": "tr",
    "name": "Türkçe",
    "message_localization": true,
    "vocabulary_translation": "when_available"
  }],
  "meta": { "count": 30, "lang": "tr" }
}
Possible results200 Locale list returned.405 Method is not GET.429 IP request limit exceeded.
NHẬN/v1/words/{word}Live · 1–5 credits

Returns one exact vocabulary record. Catalog and translated records cost 1 credit; enriched records cost 5 credits.

Parameters

TênLocationTypeBắt buộcRules and meaning
wordPathstringCóExact word or slug; maximum 120 characters. URL-encode special characters.
languagesQuerystringNoComma-separated translation codes, for example tr,de,fr.
langQuerystringNoHuman-readable message language; not a vocabulary filter.

Yêu cầu mẫu

Vỏ
curl "https://api.wordlyenglish.com/v1/words/water?languages=tr,de" \
  -H "Authorization: Bearer $WORDLY_API_KEY" \
  -H "Accept: application/json"

200 · Success

{
  "data": {
    "id": "water",
    "word": "water",
    "part_of_speech": "noun",
    "level": "basic",
    "definition": "A clear liquid essential for life.",
    "example": "Please drink enough water every day.",
    "translations": { "tr": "su", "de": "Wasser" },
    "categories": ["nature", "daily-life"],
    "media": {
      "image_url": "https://media.example/water.webp",
      "audio_url": "https://media.example/water.mp3",
      "attribution": {}
    },
    "completeness": "enriched"
  },
  "meta": {
    "credits_used": 5,
    "request_id": "5ebac760-cdc5-4a73-a87b-22463d81483c",
    "lang": "en"
  }
}

404 · Word unavailable

{
  "error": { "code": "word_not_found", "message": "The requested word was not found." },
  "meta": { "lang": "en" }
}
Possible results200 Exact record returned.401 Invalid API key.402 Insufficient credits.404 Word not found.422 Word too long.429 Rate limit exceeded.
NHẬN/v1/words/randomLive · 1 credit per requested slot

Returns random active words for quizzes, discovery feeds, and practice sessions.

Query parameters

TênTypeBắt buộcDefault / limitMô tả
countintegerNo1; min 1, max 20Requested slots and credit cost.
levelstringNoExact valueLevel filter.
part_of_speech / posstringNoExact valueGrammatical-class filter.
categorystringNoExact valueCategory filter.
languagesstringNoComma-separatedTranslations to include.

Yêu cầu mẫu

curl "https://api.wordlyenglish.com/v1/words/random?count=3&level=basic&languages=tr" \
  -H "Authorization: Bearer $WORDLY_API_KEY"

200 · Success

{
  "data": [{ "id": "water", "word": "water", "part_of_speech": "noun", "level": "basic", "definition": null, "example": null, "translations": { "tr": "su" }, "categories": [], "media": { "image_url": null, "audio_url": null, "attribution": {} }, "completeness": "translated" }],
  "meta": { "credits_used": 3, "request_id": "...", "lang": "en", "count": 1 }
}
Possible results200 Random array returned.401 Invalid API key.402 Balance below requested count.429 Rate limit exceeded.
POST/v1/words/batchLive · calculated

Looks up 1–50 unique words while preserving request order. Each enriched result costs 5 credits, another found result costs 1, and the minimum request charge is 1.

Tiêu đề

TênBắt buộcValue
AuthorizationCóBearer wly_live_...
Content-TypeCóapplication/json
AcceptĐược đề xuấtapplication/json

JSON body

FieldTypeBắt buộcRulesMô tả
wordsstring[]Có1–50 items; each max 120 charsWords to resolve; duplicates are normalized and removed.
languagesstring[]NoSupported locale codesTranslations to include.

Yêu cầu mẫu

curl -X POST "https://api.wordlyenglish.com/v1/words/batch?lang=tr" \
  -H "Authorization: Bearer $WORDLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"words":["water","not-a-word"],"languages":["tr","de"]}'

200 · Success

{
  "data": [
    { "query": "water", "found": true, "word": { "id": "water", "word": "water", "part_of_speech": "noun", "level": "basic", "definition": null, "example": null, "translations": { "tr": "su", "de": "Wasser" }, "categories": [], "media": { "image_url": null, "audio_url": null, "attribution": {} }, "completeness": "translated" } },
    { "query": "not-a-word", "found": false, "word": null }
  ],
  "meta": { "credits_used": 1, "request_id": "...", "lang": "tr", "count": 2 }
}

422 · Invalid body

{
  "error": { "code": "invalid_request", "message": "Provide between 1 and 50 words." },
  "meta": { "lang": "en" }
}
Possible results200 Ordered results.401 Invalid API key.402 Insufficient credits.413 Body over 64 KB.415 Content-Type is not JSON.422 Invalid words array.429 Rate limit exceeded.

Response field reference

Every stable response variable is described below. Additive fields may appear later, so clients should ignore fields they do not recognize.

Vocabulary object

FieldTypeNullableMô tả
idstringNoStable URL-safe slug.
wordstringNoCanonical English word.
part_of_speechstringCóGrammatical class.
levelstringCóLearning difficulty or catalog level.
definitionstringCóConcise English definition.
examplestringCóNatural example sentence.
phoneticstringCóPronunciation transcription when available.
translationsobject<string,string>NoLocale codes mapped to translations; may be empty.
synonymsstring[]NoAvailable synonyms.
antonymsstring[]NoAvailable antonyms.
categoriesstring[]NoLearning or semantic categories.
media.image_urlURL stringCóLearning image URL.
media.audio_urlURL stringCóPronunciation audio URL.
media.attributionobjectNoRequired media attribution metadata.
completenessenumNocatalog, translated, or enriched.

Meta object

FieldTypeWhen presentMô tả
credits_usedintegerMetered responsesCredits charged by this request.
request_idUUID stringMetered successSupport and billing trace ID.
langstringAlwaysSelected message locale.
countintegerList responsesNumber of response items.
next_cursorstring or nullSearchNext page cursor; null means final page.

Error object

FieldTypeMô tả
error.codestringStable machine-readable code.
error.messagestringLocalized human-readable explanation.
error.upgrade_urlstringRelative billing URL on a 402 result.
meta.langstringError-message locale.

Lỗi

HTTPMãÝ nghĩaHành động của khách hàng
401invalid_api_keyKhóa bị thiếu, không đúng định dạng, bị thu hồi hoặc không hoạt động.Kiểm tra tiêu đề Bearer hoặc thay thế khóa.
402credits_exhaustedTài khoản thiếu tín dụng cho hoạt động.Dừng thử lại và hướng dẫn khách hàng thanh toán.
404not_foundĐiểm cuối được yêu cầu không có sẵn.Kiểm tra đường dẫn và phiên bản API.
404word_not_foundMục nhập từ vựng được yêu cầu không có sẵn.Kiểm tra chính tả hoặc sử dụng tìm kiếm.
422invalid_requestMột tham số hoặc nội dung lô không hợp lệ.Hãy sửa yêu cầu trước khi thử lại.
405method_not_allowedThe endpoint does not accept the HTTP method.Use the documented GET or POST method.
413payload_too_largeThe JSON request body exceeds 64 KB.Reduce the batch body.
415unsupported_media_typeThe batch request is not JSON.Send Content-Type: application/json.
429rate_limit_exceededKhóa API đã vượt quá 120 yêu cầu mỗi phút.Wait for Retry-After.
5xxserver_errorMột lỗi phía máy chủ không mong muốn.Thử lại với thời gian chờ; liên hệ với bộ phận hỗ trợ nếu vẫn tiếp tục.

Chính sách thử lại được đề xuất

Đừng thử lại 401, 402, or 404 tự động. Dành cho thoáng qua 5xx phản hồi, hãy sử dụng thời gian chờ theo cấp số nhân với jitter và giới hạn thử lại nghiêm ngặt. Không bao giờ tạo vòng thử lại không giới hạn vì mỗi yêu cầu được xác thực được chấp nhận có thể tiêu tốn tín dụng.

JavaScript / Node.js

const response = await fetch('https://api.wordlyenglish.com/v1/account', {
  headers: {
    Authorization: `Bearer ${process.env.WORDLY_API_KEY}`,
    Accept: 'application/json'
  }
});

const body = await response.json();
if (!response.ok) {
  throw new Error(`${body.error.code}: ${body.error.message}`);
}

console.log(body.data.credits_remaining);

Python

import os
import requests

response = requests.get(
    'https://api.wordlyenglish.com/v1/account',
    headers={
        'Authorization': f'Bearer {os.environ["WORDLY_API_KEY"]}',
        'Accept': 'application/json',
    },
    timeout=15,
)
response.raise_for_status()
print(response.json()['data']['credits_remaining'])

PHP

$curl = curl_init('https://api.wordlyenglish.com/v1/account');
curl_setopt_array($curl, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 15,
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer ' . getenv('WORDLY_API_KEY'),
    'Accept: application/json',
  ],
]);

$body = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);

if ($status >= 400) {
  throw new RuntimeException('Wordly API request failed');
}
$data = json_decode($body, true, flags: JSON_THROW_ON_ERROR);

Phi tiêu / rung

Không gửi khóa Wordly bên trong ứng dụng Flutter. Ví dụ này thuộc về chức năng máy chủ hoặc chương trình phụ trợ Dart đáng tin cậy.

final response = await http.get(
  Uri.parse('https://api.wordlyenglish.com/v1/account'),
  headers: {
    'Authorization': 'Bearer ${Platform.environment['WORDLY_API_KEY']}',
    'Accept': 'application/json',
  },
);

final body = jsonDecode(response.body) as Map<String, dynamic>;
if (response.statusCode >= 400) {
  throw Exception((body['error'] as Map)['code']);
}

Danh sách kiểm tra sản xuất

  • Proxy Wordly yêu cầu thông qua một chương trình phụ trợ đáng tin cậy.
  • Đặt thời gian chờ kết nối và phản hồi.
  • xử lý 401, 402, 404, and 5xx riêng biệt.
  • Query GET /v1/account when your application needs the current balance.
  • Ghi nhật ký điểm cuối, trạng thái, độ trễ và request_id mà không cần đăng nhập khóa API.
  • Sử dụng các khóa riêng biệt cho mỗi môi trường và xoay chúng theo định kỳ.
  • Cache stable vocabulary responses in your backend when appropriate.

Sẵn sàng thực hiện yêu cầu đầu tiên của bạn?

Tạo một tài khoản, xác minh email của bạn và nhận 50 tín dụng miễn phí.

Tạo tài khoản miễn phí

Cần trợ giúp tích hợp? Email [email protected].