スコープ契約に関する注意: Public routes enforce API key scopes。必要な grants は スコープリファレンス を参照してください。

はじめに

VoiceAgent API key を使って、バックエンドサービスから公開 v1 API を呼び出します。

Base URL

公開 API は URL のメジャーバージョンで管理されます。本番ドメインが確定するまでは、 例では次の Base URL を使用してください。

https://api.voiceagent.example/api/v1/

クイックスタート

  1. Dashboard を開き、/api-keys に移動します。
  2. key を作成し、secret value をコピーします。VoiceAgent API keys は vak_ で始まります。
  3. バックエンドから GET /api/v1/agents を呼び出します。

cURL

export VOICEAGENT_API_KEY="vak_replace_with_your_key"

curl -sS "https://api.voiceagent.example/api/v1/agents" \
  -H "Authorization: Bearer ${VOICEAGENT_API_KEY}"

Node.js

const apiKey = process.env.VOICEAGENT_API_KEY;

if (!apiKey) {
  throw new Error("Set VOICEAGENT_API_KEY to your vak_ API key");
}

const response = await fetch("https://api.voiceagent.example/api/v1/agents", {
  headers: {
    Authorization: `Bearer ${apiKey}`,
  },
});

const body = await response.json();

if (!response.ok) {
  throw new Error(`${response.status} ${body.error?.code}: ${body.error?.message}`);
}

console.log(body);

Python

import os
import requests

api_key = os.environ["VOICEAGENT_API_KEY"]

response = requests.get(
    "https://api.voiceagent.example/api/v1/agents",
    headers={"X-API-Key": api_key},
    timeout=30,
)
response.raise_for_status()

print(response.json())

認証ヘッダー

VoiceAgent は API key 認証に次のどちらのヘッダーも受け付けます。

Authorization: Bearer vak_...
X-API-Key: vak_...

新しい連携では Authorization: Bearer を優先してください。 X-API-Key は bearer auth の設定が難しい環境向けにサポートされています。

次のステップ

key の扱いについては 認証、標準の error envelope については エラーハンドリング、一覧画面を実装する前には ページネーション を確認してください。