Free Dictionary API 数据源
数据

Free Dictionary API 数据源

Use when the user asks for word definitions, meanings, translations, pronunciations, synonyms, or antonyms (keywords:单词释义、词义、翻译、音标、近义词、反义词、definition、meaning、synonym、antonym、pronunciation). Do NOT use for general web search, news, or non-dictionary data.

hustcc
hustcc
浏览4万
使用1

Skill 文件

SKILL.md
name
free-dictionary-datasource
title
Free Dictionary API 数据源
description
Use when the user asks for word definitions, meanings, translations, pronunciations, synonyms, or antonyms (keywords:单词释义、词义、翻译、音标、近义词、反义词、definition、meaning、synonym、antonym、pronunciation). Do NOT use for general web search, news, or non-dictionary data.
tools
curl

Free Dictionary API 数据源

通过 curl tool 或 JavaScript fetch 调用 Free Dictionary API 获取单词的定义、音标、发音、词源、同义词/反义词等信息。

鉴权

Free Dictionary API 是免费开源项目,无需任何 API Key 或鉴权,直接发送 HTTP 请求即可使用,不要传 token 或 API key。

通用约定

  • Base URLhttps://api.dictionaryapi.dev/api/v2/entries(必须使用 HTTPS,HTTP 会被系统拒绝)
  • 请求方法:GET
  • 响应格式:JSON(数组格式,即使查询单个单词)
  • URL 结构{base_url}/{language}/{word}
  • 支持语言en(英语)、es(西班牙语)、fr(法语)、de(德语)、it(意大利语)、pt(葡萄牙语)、ru(俄语)、zh(中文)等
  • 分页:不分页,一次返回完整数据
  • 速率限制:无严格限流,但应合理使用,避免高频请求

⚠️ 速率限制策略(必须遵守)

  1. 串行请求:同一时间只发 1 个请求,等返回后再发下一个。严禁并行发送多个请求
  2. 请求间隔:每两个请求之间至少间隔 1 秒
  3. 批量查询:需要查多个单词时,一次最多查 3 个,如需更多则分批
  4. 429/503 重试:收到 429 或 503 错误后等待 5 秒再重试,严禁立即重试
  5. 数据复用:已获取的单词释义结果应缓存使用,不要重复请求相同单词

常用接口

1. 获取单词定义

GET https://api.dictionaryapi.dev/api/v2/entries/{language}/{word}

参数

参数名位置必填说明
languagepath语言代码,如 enesfrde
wordpath要查询的单词

关键返回字段

JSON Path类型说明
[0].wordstring查询的单词本身
[0].phoneticstring标准音标
[0].phonetics[].textstring音标文本
[0].phonetics[].audiostring发音音频 URL(可能为空)
[0].originstring词源信息
[0].meanings[].partOfSpeechstring词性(noun/verb/adj/adv/exclamation 等)
[0].meanings[].definitions[].definitionstring定义解释
[0].meanings[].definitions[].examplestring例句
[0].meanings[].definitions[].synonymsarray同义词列表
[0].meanings[].definitions[].antonymsarray反义词列表
[0].meanings[].synonymsarray该词性下的同义词
[0].meanings[].antonymsarray该词性下的反义词

注意:响应是一个数组,即使只查询一个单词。如果单词不存在或不可用,API 返回 404 错误。


2. 获取多语言单词定义

GET https://api.dictionaryapi.dev/api/v2/entries/{language}/{word}

常用语言代码

语言代码语言
en英语
es西班牙语
fr法语
de德语
it意大利语
pt葡萄牙语
ru俄语
zh中文
hi印地语
ar阿拉伯语
ja日语
ko韩语

curl 调用示例

场景 1:查询英文单词 "hello" 的定义

  1. 调用接口:
curl(url = "https://api.dictionaryapi.dev/api/v2/entries/en/hello", X = "GET")
  1. 典型响应示例(简化):
json
[  {    "word": "hello",    "phonetic": "həˈləʊ",    "phonetics": [      {        "text": "həˈləʊ",        "audio": "//ssl.gstatic.com/dictionary/static/sounds/20200429/hello--_gb_1.mp3"      }    ],    "origin": "early 19th century: variant of earlier hollo...",    "meanings": [      {        "partOfSpeech": "exclamation",        "definitions": [          {            "definition": "used as a greeting or to begin a phone conversation.",            "example": "hello there, Katie!",            "synonyms": [],            "antonyms": []          }        ]      },      {        "partOfSpeech": "noun",        "definitions": [          {            "definition": "an utterance of 'hello'; a greeting.",            "example": "she was getting polite nods and hellos from people",            "synonyms": ["greeting", "welcome"],            "antonyms": ["goodbye"]          }        ]      }    ]  }]
  1. 从返回中提取信息:
    • [0].phonetic → 音标:həˈləʊ
    • [0].phonetics[0].audio → 发音音频链接(补全为 https: 前缀)
    • [0].meanings[0].partOfSpeech → 词性:exclamation(感叹词)
    • [0].meanings[0].definitions[0].definition → 定义:"used as a greeting..."
    • [0].meanings[0].definitions[0].example → 例句:"hello there, Katie!"
    • [0].origin → 词源信息

场景 2:查询带有同义词/反义词的单词

以 "happy" 为例:

curl(url = "https://api.dictionaryapi.dev/api/v2/entries/en/happy", X = "GET")

从返回中提取:

  • [0].meanings[].definitions[].synonyms → 同义词列表
  • [0].meanings[].definitions[].antonyms → 反义词列表

场景 3:查询非英语单词(如西班牙语 "amor")

curl(url = "https://api.dictionaryapi.dev/api/v2/entries/es/amor", X = "GET")

JavaScript 调用方式

除了使用 curl 工具外,也可以在代码环境中使用 JavaScript 的 fetch() 进行请求:

基本用法

javascript
// 查询英文单词定义const response = await fetch('https://api.dictionaryapi.dev/api/v2/entries/en/hello');const data = await response.json();
// data 是一个数组,第一个元素包含完整定义console.log(data[0].word);        // "hello"console.log(data[0].phonetic);    // "həˈləʊ"console.log(data[0].meanings);    // 词义和定义数组

完整示例:查询并格式化输出

javascript
async function getWordDefinition(word, language = 'en') {  try {    const response = await fetch(      `https://api.dictionaryapi.dev/api/v2/entries/${language}/${encodeURIComponent(word)}`    );        if (!response.ok) {      if (response.status === 404) {        return { error: `未找到单词 "${word}" 的定义` };      }      throw new Error(`HTTP ${response.status}`);    }        const data = await response.json();    const wordData = data[0];        // 格式化输出    return {      word: wordData.word,      phonetic: wordData.phonetic,      audio: wordData.phonetics.find(p => p.audio)?.audio,      meanings: wordData.meanings.map(m => ({        partOfSpeech: m.partOfSpeech,        definitions: m.definitions.map(d => ({          definition: d.definition,          example: d.example,          synonyms: d.synonyms,          antonyms: d.antonyms        }))      })),      origin: wordData.origin    };  } catch (error) {    return { error: error.message };  }}
// 使用示例const result = await getWordDefinition('hello', 'en');console.log(JSON.stringify(result, null, 2));

多语言查询示例

javascript
// 查询西班牙语单词const esResponse = await fetch('https://api.dictionaryapi.dev/api/v2/entries/es/amor');const esData = await esResponse.json();
// 查询法语单词const frResponse = await fetch('https://api.dictionaryapi.dev/api/v2/entries/fr/amour');const frData = await frResponse.json();

错误处理

javascript
async function safeFetchWord(word, language = 'en') {  try {    const response = await fetch(      `https://api.dictionaryapi.dev/api/v2/entries/${language}/${encodeURIComponent(word)}`    );        if (response.status === 404) {      console.log(`"${word}" 未找到,请检查拼写`);      return null;    }        if (response.status === 429) {      console.log('请求过于频繁,请稍后重试');      await new Promise(r => setTimeout(r, 5000)); // 等待 5 秒      return safeFetchWord(word, language); // 重试    }        const data = await response.json();    return data;      } catch (error) {    console.error('请求失败:', error);    return null;  }}

音频链接处理

API 返回的音频 URL 可能省略协议前缀,需要补全:

javascript
const audioUrl = data[0].phonetics[0].audio;// 可能返回 "//ssl.gstatic.com/..." 或 "https://ssl.gstatic.com/..."const fullAudioUrl = audioUrl.startsWith('//')   ? `https:${audioUrl}`   : audioUrl;

错误处理

HTTP 状态码含义应对方式
200成功正常处理返回的 JSON 数据
404单词未找到提示用户 "未找到该单词的定义,请检查拼写或尝试其他单词"
429请求过多等待 5 秒后重试,降低请求频率
503服务不可用等待 5 秒后重试
500服务器错误稍后重试或提示用户服务暂时不可用

使用提示

  1. 音频链接处理:API 返回的音频 URL 可能省略 https: 前缀,使用前需补全为完整 URL(如 https://ssl.gstatic.com/...
  2. 多词性处理:一个单词可能有多个词性(如 hello 可作感叹词、名词、动词),遍历 meanings 数组获取所有定义
  3. 数组响应:响应始终是数组,即使只查询一个单词,取 [0] 即可
  4. 空数据处理synonymsantonyms 可能为空数组,example 可能不存在,需做空值判断
Ln 1, Col 1MarkdownSpaces: 2
No errors