すべてのプロダクト
Search
ドキュメントセンター

Tablestore:API キー管理

最終更新日:Jun 18, 2026

Tablestore は、Knowledge Store と Memory Store へのアクセスに API キー認証をサポートしています。API キーは AccessKey ペアを管理することなく独立して作成および失効させることができ、HTTPS によるトランスポートが必要です。

認証方式

Tablestore は次の認証方式をサポートしています。

認証方式

ユースケース

サポートされる API

AccessKey (AK/SK)

すべての機能へのフルアクセス

すべての Tablestore API

API キー

キーペアを管理せずに AI アプリケーションを統合

Knowledge Store と Memory Store の API のみ

API キーの作成

  1. Tablestore コンソールにログオンします。

  2. 左側メニューで、[API Key] をクリックします。

  3. API Key Management ページで、[Create API Key] をクリックします。

  4. Create API Key ダイアログボックスで、[Expiration Time] を設定します。

  5. [Create] をクリックします。

重要

キーの値は安全な場所に保管してください。キーの値は作成時にのみ表示され、後から取得することはできません。

API キーの使用

SDK または curl を使用して、API キーで Knowledge Store と Memory Store にアクセスします。API キーは、両方のサービスのすべての API オペレーションに対応しています。

説明

API キーによるアクセスには HTTPS エンドポイントが必要です。

SDK

Knowledge Store と Memory Store には、Python と TypeScript の SDK が用意されています。クライアントを初期化するには、AccessKey 認証情報の代わりに api_key パラメータを使用します。

Python

SDK をインストールします。

pip install tablestore-agent-storage

次の例では、API キーを使用してナレッジベースを作成し、セマンティック検索を実行します。

from tablestore_agent_storage import AgentStorageClient

# API キーを使用してクライアントを初期化
client = AgentStorageClient(
    api_key="your-api-key",
    ots_endpoint="https://your-instance.cn-beijing.ots.aliyuncs.com",
    ots_instance_name="your-instance-name",
)

# ナレッジベースを作成
client.create_knowledge_base({"knowledgeBaseName": "product_docs"})

# ナレッジベースをリスト
response = client.list_knowledge_base()
for kb in response["data"]["knowledgeBases"]:
    print(kb["knowledgeBaseName"])

# ナレッジベースから取得
results = client.retrieve({
    "knowledgeBaseName": "product_docs",
    "retrievalQuery": {"type": "TEXT", "text": "your query"}
})
for item in results["data"]["retrievalResults"]:
    print(item["content"])

TypeScript

SDK をインストールします。

npm install @tablestore/agent-storage

次の例では、API キーを使用してナレッジベースを作成し、セマンティック検索を実行します。

import { AgentStorageClient } from '@tablestore/agent-storage';

// API キーを使用してクライアントを初期化
const client = new AgentStorageClient({
  apiKey: 'your-api-key',
  endpoint: 'https://your-instance.cn-beijing.ots.aliyuncs.com',
  instanceName: 'your-instance-name',
});

// ナレッジベースを作成
await client.createKnowledgeBase({ knowledgeBaseName: 'product_docs' });

// ナレッジベースをリスト
const response = await client.listKnowledgeBase({});
for (const kb of response.data.knowledgeBases) {
  console.log(kb.knowledgeBaseName);
}

// ナレッジベースから取得
const results = await client.retrieve({
  knowledgeBaseName: 'product_docs',
  retrievalQuery: { type: 'TEXT', text: 'your query' },
});
for (const item of results.data.retrievalResults) {
  console.log(item.content);
}

curl

HTTP リクエストに x-ots-apikeyx-ots-instancename ヘッダーを追加します。

次の例では、curl を使用してナレッジベースを作成します。

curl -X POST 'https://your-instance.cn-beijing.ots.aliyuncs.com/CreateKnowledgeBase' \
  -H 'x-ots-instancename: your-instance-name' \
  -H 'x-ots-apikey: your-api-key' \
  -H 'Content-Type: application/json' \
  -d '{"knowledgeBaseName": "product_docs"}'

次の例では、curl を使用してすべてのナレッジベースを一覧表示します。

curl -X POST 'https://your-instance.cn-beijing.ots.aliyuncs.com/ListKnowledgeBase' \
  -H 'x-ots-instancename: your-instance-name' \
  -H 'x-ots-apikey: your-api-key' \
  -H 'Content-Type: application/json' \
  -d '{}'

制限事項

  • API キーは Knowledge Store と Memory Store の API のみに対応しています。その他の Tablestore API にアクセスするには、AccessKey 認証を使用してください。

  • API キーを作成すると、AliyunOTSFullAccess ポリシーが割り当てられた専用の RAM ユーザーが作成されます。API キーは、この RAM ユーザーの権限を継承します。権限を調整するには、RAM コンソールでユーザーポリシーを変更してください。

  • RAM ユーザーに API オペレーション権限または ots:CallWithBearerToken 権限のいずれかが不足している場合、API キーを使用した Knowledge Store と Memory Store へのリクエストは失敗します。