コンテンツにスキップ

Azure OpenAI

Azure OpenAI は、データに自然言語アルゴリズムを適用することを可能にします。

エンドポイント

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/azure-openai/{resource_name}/{deployment_name}

必要なもの

Azure OpenAI にリクエストを送信する際に必要なものは次のとおりです:

  • AI Gateway アカウント ID
  • AI Gateway ゲートウェイ名
  • Azure OpenAI API キー
  • Azure OpenAI リソース名
  • Azure OpenAI デプロイメント名(モデル名とも呼ばれます)

URL 構造

新しいベース URL は、上記のデータを使用して次の構造になります:https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/azure-openai/{resource_name}/{deployment_name}。その後、ベース URL の末尾にエンドポイントと api-version を追加できます。例:.../chat/completions?api-version=2023-05-15

例 fetch リクエスト
curl 'https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/azure-openai/{resource_name}/{deployment_name}/chat/completions?api-version=2023-05-15' \
--header 'Content-Type: application/json' \
--header 'api-key: {azure_api_key}' \
--data '{
"messages": [
{
"role": "user",
"content": "Cloudflare とは何ですか?"
}
]
}'

openai-node ライブラリを使用している場合、エンドポイントを次のように設定できます:

JavaScript
import OpenAI from "openai";
const resource = "xxx";
const model = "xxx";
const apiVersion = "xxx";
const apiKey = env.AZURE_OPENAI_API_KEY;
const accountId = "{account_id}";
const gatewayId = "{gateway_id}";
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/azure-openai/${resource}/${model}`;
const azure_openai = new OpenAI({
apiKey,
baseURL,
defaultQuery: { "api-version": apiVersion },
defaultHeaders: { "api-key": apiKey },
});