テキスト・文字列

テンプレート

{{variable}} 形式のテンプレート文字列に変数を埋め込みます。ドット記法(例: {{user.name}})でネストしたオブジェクトにも対応します。未定義の変数はプレースホルダーのまま残し、variables_missing に一覧します。

MCPツール名: render_template

POST /v1/template/render

パラメータ:

パラメータ必須説明
templatestringレンダリングするテンプレート文字列(最大100KB)
variablesobject-置換に使う変数オブジェクト(省略時は空オブジェクト)

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/template/render" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "こんにちは、{{name}}さん。",
    "variables": {"name": "山田太郎"}
  }'

レスポンス例:

{
  "rendered": "こんにちは、山田太郎さん。",
  "variables_missing": []
}

レスポンス:

未定義の変数がある場合、rendered には {{variable}} プレースホルダーが残り、variables_missing にパスが含まれます。数値・真偽値は文字列に変換されます。

文字列ケース変換

camel・snake・kebab・pascal・constant・title 等に相互変換します。入力ケースを自動検出。to=all で全ケースを一括取得可能。

MCPツール名: convert_string_case

GET /v1/string/case

パラメータ:

パラメータ必須説明
textstring変換する文字列
tostringcamel / snake / kebab / pascal / constant / title / lower / upper / all

リクエスト例:

curl "https://api.thousand-api.com/v1/string/case?text=hello_world_foo&to=camel" \
  -H "x-api-key: YOUR_API_KEY"

レスポンス例:

{
  "text": "hello_world_foo",
  "to": "camel",
  "detected_case": "snake",
  "result": "helloWorldFoo"
}

レスポンス:

to=all の場合、result は各ケース名をキーとするオブジェクトになります。日本語を含む文字列は lower / upper のみ変換し、それ以外のケースは入力をそのまま返します。

ランダム文字列生成

暗号学的に安全なランダム文字列を生成します。文字セット・長さ・生成個数を指定可能。Node.js標準crypto使用。

MCPツール名: generate_random_string

GET /v1/random/string

パラメータ:

パラメータ必須説明
lengthinteger-文字数(デフォルト: 16・最大: 128)
charsetstring-alphanumeric / alphabetic / numeric / hex / urlsafe / uppercase
countinteger-生成個数(デフォルト: 1・最大: 10)

リクエスト例:

curl "https://api.thousand-api.com/v1/random/string?length=8&charset=uppercase&count=3" \
  -H "x-api-key: YOUR_API_KEY"

レスポンス例:

{
  "length": 8,
  "charset": "uppercase",
  "count": 3,
  "results": ["AB3K7MN2", "PQ9XL4WZ", "R7MN2PQ9"]
}

レスポンス:

生成された文字列はセッショントークン・一時パスワード・招待コード等に使用できます。本番環境での暗号鍵生成には、用途に応じた適切な鍵生成方法(例: crypto.generateKeyPair)を使用してください。

テキスト統計

HTMLからプレーンテキストを抽出したり、テキストの文字数・単語数・段落数・推定読了時間を返したり、2つのテキスト間の差分を計算したり、人間が読めるタイトルからURLセーフなスラッグを生成します。

MCPツール名: extract_text_from_html, get_text_stats, diff_text, generate_slug

POST /v1/text/html-to-text

パラメータ:

パラメータ必須説明
htmlstringHTMLテキスト(最大1MB)
max_lengthinteger-出力テキストの最大文字数(正の整数)
preserve_linksboolean-trueのときリンク一覧(text / href)を返す(デフォルトfalse)

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/text/html-to-text" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello</h1><p>Visit <a href=\"https://example.com\">Example</a></p>",
    "max_length": 500,
    "preserve_links": true
  }'

レスポンス例:

{
  "text": "Hello\n\nVisit Example",
  "char_count": 19,
  "truncated": false,
  "links": [
    {
      "text": "Example",
      "href": "https://example.com"
    }
  ]
}

レスポンスフィールド:

パラメータ説明
textタグ除去・エンティティデコード・空白正規化済みのプレーンテキスト
char_counttextの文字数
truncatedmax_lengthによりテキストが切り詰められた場合true
linkspreserve_links: true のときのみ。{ text, href } の配列

レスポンス:

script / style タグとその中身は完全に除去されます。ブロック要素(p, div, h1〜h6, li 等)は改行に変換され、3行以上の連続改行は2行に圧縮されます。Scraperで取得したHTMLのトークン削減に使えます。

POST /v1/text/stats

パラメータ:

パラメータ必須説明
textstring解析するテキスト(最大100KB)
langstring-言語コード(ja / en・デフォルトen)

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/text/stats" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "AIエージェントに確実性を与えるMCPサーバー。",
    "lang": "ja"
  }'

レスポンス例:

{
  "characters": 22,
  "characters_no_spaces": 22,
  "words": 22,
  "sentences": 1,
  "paragraphs": 1,
  "reading_time_seconds": 3
}

レスポンスフィールド:

パラメータ説明
characters全文字数(スペース・改行含む)
characters_no_spacesスペース・タブ・改行を除いた文字数
words単語数(ja: 空白除く文字数 / en: スペース区切り)
sentences文数(ja: 。!? / en: .!?)
paragraphs段落数(空行で区切る)
reading_time_seconds推定読了時間(秒・切り上げ)

レスポンス:

読了速度: ja は 500文字/分(characters_no_spaces)、en は 225単語/分(words)。外部APIへの依存なし。

POST /v1/text/diff

パラメータ:

パラメータ必須説明
originalstring比較元テキスト(最大256KB)
modifiedstring比較先テキスト(最大256KB)
context_linesinteger-差分前後に含める文脈行数(0〜10・デフォルト3)
formatstring-出力形式(unified / json・デフォルトunified)

例: format "unified"(unified diff 文字列)

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/text/diff" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "original": "line1\nline2\nline3\n",
    "modified": "line1\nline3\nline4\n",
    "context_lines": 3,
    "format": "unified"
  }'

レスポンス例:

{
  "diff": "===================================================================\n@@ -1,3 +1,3 @@\n line1\n-line2\n line3\n+line4\n",
  "added_lines": 1,
  "removed_lines": 1,
  "has_changes": true
}

例: format "json"(構造化データ)

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/text/diff" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "original": "alpha\nbeta\n",
    "modified": "alpha\ngamma\n",
    "format": "json"
  }'

レスポンス例:

{
  "diff": [
    { "type": "unchanged", "lines": ["alpha"] },
    { "type": "removed", "lines": ["beta"] },
    { "type": "added", "lines": ["gamma"] }
  ],
  "added_lines": 1,
  "removed_lines": 1,
  "has_changes": true
}

レスポンスフィールド:

パラメータ説明
diffformat: unified なら unified diff 文字列(--- / +++ ヘッダー行は除去済み)。format: json なら { type, lines } の配列
added_lines追加された行数
removed_lines削除された行数
has_changes差分が存在する場合 true

レスポンス:

行単位の差分計算。コードレビュー、AI生成テキストと原文の比較、ドキュメント改訂の要約に使えます。MCPツール名: diff_text

POST /v1/text/slugify

パラメータ:

パラメータ必須説明
textstringスラッグ化するテキスト(最大1000文字)
localestring-ja(デフォルト): 日本語をヘボン式ローマ字に変換してからスラッグ化。en 等: ローマ字変換をスキップ
separatorstring-単語区切り(- / _ / .・デフォルト -)
max_lengthinteger-スラッグの最大文字数(1〜200)
lowercaseboolean-小文字化(デフォルト true)

convert_string_case(GET /v1/string/case)は既存の英数字識別子のケース変換(camel / snake / kebab 等)向けで、日本語は lower / upper のみ対応します。本APIは日本語タイトルからURLパス・ドキュメントID・ナビゲーションキーを生成する用途向けで、locale: ja のとき kuromoji + kuroshiro でローマ字化してから正規化します。

MCPツール名: generate_slug

例1: 日本語タイトル(locale: ja)

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/text/slugify" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Thousand API — 祝日カレンダー機能",
    "locale": "ja"
  }'

レスポンス例:

{
  "input": "Thousand API — 祝日カレンダー機能",
  "slug": "thousand-api-shukujitsu-karendaa-kinou",
  "truncated": false,
  "char_replaced": ["—"]
}

例2: 英語テキスト(locale: en)

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/text/slugify" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello World! This is a Test.",
    "locale": "en"
  }'

レスポンス例:

{
  "input": "Hello World! This is a Test.",
  "slug": "hello-world-this-is-a-test",
  "truncated": false,
  "char_replaced": ["!", "."]
}

例3: separator と max_length の指定

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/text/slugify" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "My Long Document Title Here And More",
    "locale": "en",
    "separator": "_",
    "max_length": 30
  }'

レスポンス例:

{
  "input": "My Long Document Title Here And More",
  "slug": "my_long_document_title_here",
  "truncated": true,
  "char_replaced": []
}

レスポンスフィールド:

パラメータ説明
inputリクエストの text をそのまま返す
slug生成されたURLセーフなスラッグ
truncatedmax_length により切り詰められた場合 true
char_replaced除去・置換された文字の一覧(重複なし・出現順)

レスポンス:

日本語処理は /v1/ja/convert と同じ Lambda(kuromoji 辞書)を使用します。初回リクエストはコールドスタートで数秒かかることがあります。

日本語変換

日本語テキストをひらがな・カタカナ・ローマ字に変換します。kuromojiによる形態素解析で固有名詞も正確に変換。

MCPツール名: convert_japanese

GET /v1/ja/convert

パラメータ:

パラメータ必須説明
textstring変換する日本語テキスト(最大1000文字)
tostringhiragana / katakana / romaji

リクエスト例:

curl "https://api.thousand-api.com/v1/ja/convert?text=%E6%9D%B1%E4%BA%AC%E9%83%BD%E6%B8%8B%E8%B0%B7%E5%8C%BA&to=hiragana" \
  -H "x-api-key: YOUR_API_KEY"

レスポンス例:

{
  "text": "東京都渋谷区",
  "to": "hiragana",
  "result": "とうきょうとしぶやく"
}

正規表現テスター

正規表現パターンをテキストに対してテストし、マッチ結果を返します。名前付きキャプチャグループ・各種フラグに対応。ReDoS対策済み。

MCPツール名: test_regex

POST /v1/regex/test

パラメータ:

パラメータ必須説明
patternstring正規表現パターン(デリミタなし)
textstringテスト対象テキスト(最大10,000文字)
flagsstring-g / i / m / s / u の組み合わせ

リクエスト例:

curl -X POST "https://api.thousand-api.com/v1/regex/test" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "pattern": "(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})",
    "text": "2026-05-29",
    "flags": ""
  }'

レスポンス例:

{
  "pattern": "(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})",
  "flags": "",
  "text": "2026-05-29",
  "matched": true,
  "match_count": 1,
  "matches": [
    {
      "value": "2026-05-29",
      "index": 0,
      "groups": {
        "year": "2026",
        "month": "05",
        "day": "29"
      }
    }
  ]
}