For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
API キー
LLM プロバイダー認証のための API キーを管理します。
Tip
ドキュメント全体を通じて、LLM プロバイダー API キーなどには、Kubernetes Secret ベースのストレージの代わりに外部シークレットストレージを使用できます。
プロバイダー API キーは、OpenAI や Anthropic などの LLM プロバイダーに対して agentgateway を認証します。キーが漏洩すると、攻撃者がお客様の負担でリクエストを実行できてしまいます。
クライアントは仮想キーで認証できます。プロキシはリクエストを転送する前に、各仮想キーをプロバイダーキーに置き換えます。キーごとのトークン予算を適用し、使用量を追跡することもできます。
プロキシにキーを提供する方法を選択します。
始める前に
クイックスタートガイドに従って Solo Enterprise for agentgateway のコントロールプレーンをインストールします。
API キーを提供する
agentgateway に API キーを提供するには、以下のオプションから選択できます。
インライントークン
EnterpriseAgentgatewayBackend の設定でトークンを直接提供します。このオプションは最も安全性が低いため、AI Gateway を試すなどの簡単なテストにのみ使用してください。
OpenAI への API キーなど、LLM プロバイダーからトークンを取得します。
export TOKEN=<your-ai-provider-token>EnterpriseAgentgatewayBackend 設定でトークンをインラインで提供します。
kubectl apply -f- <<EOF apiVersion: enterpriseagentgateway.solo.io/v1alpha1 kind: EnterpriseAgentgatewayBackend metadata: name: openai namespace: agentgateway-system spec: ai: provider: openai: {} #optionally pin the model or other OpenAI settings #model: gpt-3.5-turbo policies: auth: key: $TOKEN ai: routes: "/v1/responses": "Responses" "/v1/chat/completions": "Completions" "/v1/models": "Models" "*": "Passthrough" EOFこの設定を理解するために以下の表を確認してください。詳細については、API リファレンスを参照してください。
設定 説明 ai.provider.openaiOpenAI プロバイダーを定義します。 openai.model使用する OpenAI モデル( gpt-3.5-turboなど)。policies.authOpenAI API の認証トークンを設定します。例ではインライントークンを使用しています。 EnterpriseAgentgatewayBackend への受信トラフィックをルーティングする HTTPRoute リソースを作成します。以下の例では、以前に作成した EnterpriseAgentgatewayBackend への
/openaiパスのルートをセットアップします。URLRewriteフィルターはパスを/openaiから使用する LLM プロバイダーの API パス/v1/chat/completionsに書き換えます。kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: openai namespace: agentgateway-system spec: parentRefs: - name: agentgateway-proxy namespace: agentgateway-system rules: - matches: - path: type: PathPrefix value: /openai filters: - type: URLRewrite urlRewrite: path: type: ReplacePrefixMatch replacePrefixMatch: /v1/chat/completions backendRefs: - name: openai namespace: agentgateway-system group: enterpriseagentgateway.solo.io kind: EnterpriseAgentgatewayBackend EOFLLM プロバイダー API にリクエストを送信します。リクエストが成功し、チャット補完 API からレスポンスが返されることを確認します。EnterpriseAgentgatewayBackend でモデルを固定していない場合は、リクエストにモデルを含めます。
curl "$INGRESS_GW_ADDRESS/openai" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "Compose a poem that explains the concept of recursion in programming." } ] }'curl "localhost:8080/openai" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "Compose a poem that explains the concept of recursion in programming." } ] }'出力例:
{ "id": "chatcmpl-AEHYs2B0XUlEioCduH1meERmMwBGF", "object": "chat.completion", "created": 1727967462, "model": "gpt-3.5-turbo-0125", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "In the world of code, a method elegant and rare,\nKnown as recursion, a loop beyond compare.\nLike a mirror reflecting its own reflection,\nIt calls upon itself with deep introspection.\n\nA function that calls itself with artful grace,\nDividing a problem into a smaller space.\nLike a nesting doll, layers deep and profound,\nIt solves complex tasks, looping around.\n\nWith each recursive call, a step is taken,\nTowards solving the problem, not forsaken.\nA dance of self-replication, a mesmerizing sight,\nUnraveling complexity with power and might.\n\nBut beware of infinite loops, a perilous dance,\nWithout a base case, it's a risky chance.\nFor recursion is a waltz with a delicate balance,\nInfinite beauty, yet a risky dalliance.\n\nSo embrace the concept, in programming's domain,\nLet recursion guide you, like a poetic refrain.\nA magical loop, a recursive song,\nIn the symphony of code, where brilliance belongs.", "refusal": null }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 39, "completion_tokens": 200, "total_tokens": 239, "prompt_tokens_details": { "cached_tokens": 0 }, "completion_tokens_details": { "reasoning_tokens": 0 } }, "system_fingerprint": null }
シークレットの API キー
API キーを Kubernetes シークレットに保存します。その後、EnterpriseAgentgatewayBackend 設定でシークレットを参照します。このオプションはインライントークンよりも安全です。API キーはエンコードされ、RBAC ルールを通じてシークレットへのアクセスを制限できるためです。インラインオプションと同様に、API キーとシークレットの作成とセットアップは比較的簡単です。このオプションは、概念実証、管理された開発・ステージング環境、またはシークレットを使用する適切に管理された本番環境で使用できます。
OpenAI API にアクセスするための API キーを作成します。別の AI プロバイダーを使用する場合は、そのプロバイダーの AI 用の API キーを作成し、これらのチュートリアルのサンプルコマンドをプロバイダーの AI API を使用するよう修正してください。
API キーを環境変数に保存します。
export OPENAI_API_KEY=<insert your API key>AI API キーを保存する Kubernetes シークレットを作成します。
kubectl apply -f- <<EOF apiVersion: v1 kind: Secret metadata: name: openai-secret namespace: agentgateway-system type: Opaque stringData: Authorization: $OPENAI_API_KEY EOFAI API キーシークレットを参照する LLM プロバイダーを設定するための EnterpriseAgentgatewayBackend リソースを作成します。
kubectl apply -f- <<EOF apiVersion: enterpriseagentgateway.solo.io/v1alpha1 kind: EnterpriseAgentgatewayBackend metadata: name: openai namespace: agentgateway-system spec: ai: provider: openai: model: gpt-3.5-turbo # Optional: specify default model # host: api.openai.com # Optional: custom host if needed # port: 443 # Optional: custom port policies: auth: secretRef: name: openai-secret EOFこの設定を理解するために以下の表を確認してください。詳細については、API リファレンスを参照してください。
設定 説明 ai.provider.openaiOpenAI プロバイダーを定義します。 openai.model使用する OpenAI モデル( gpt-3.5-turboなど)。policies.authOpenAI API の認証トークンを設定します。例では以前に作成したシークレットを参照しています。 EnterpriseAgentgatewayBackend への受信トラフィックをルーティングする HTTPRoute リソースを作成します。以下の例では、以前に作成した EnterpriseAgentgatewayBackend への
/openaiパスのルートをセットアップします。kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: openai namespace: agentgateway-system spec: parentRefs: - name: agentgateway-proxy namespace: agentgateway-system rules: - matches: - path: type: PathPrefix value: /openai backendRefs: - name: openai namespace: agentgateway-system group: enterpriseagentgateway.solo.io kind: EnterpriseAgentgatewayBackend EOFLLM プロバイダー API にリクエストを送信します。リクエストが成功し、チャット補完 API からレスポンスが返されることを確認します。EnterpriseAgentgatewayBackend でモデルを固定していない場合は、リクエストにモデルを含めます。
curl "$INGRESS_GW_ADDRESS/openai" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "Compose a poem that explains the concept of recursion in programming." } ] }'curl "localhost:8080/openai" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "Compose a poem that explains the concept of recursion in programming." } ] }'出力例:
{ "id": "chatcmpl-AEHYs2B0XUlEioCduH1meERmMwBGF", "object": "chat.completion", "created": 1727967462, "model": "gpt-3.5-turbo-0125", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "In the world of code, a method elegant and rare,\nKnown as recursion, a loop beyond compare.\nLike a mirror reflecting its own reflection,\nIt calls upon itself with deep introspection.\n\nA function that calls itself with artful grace,\nDividing a problem into a smaller space.\nLike a nesting doll, layers deep and profound,\nIt solves complex tasks, looping around.\n\nWith each recursive call, a step is taken,\nTowards solving the problem, not forsaken.\nA dance of self-replication, a mesmerizing sight,\nUnraveling complexity with power and might.\n\nBut beware of infinite loops, a perilous dance,\nWithout a base case, it's a risky chance.\nFor recursion is a waltz with a delicate balance,\nInfinite beauty, yet a risky dalliance.\n\nSo embrace the concept, in programming's domain,\nLet recursion guide you, like a poetic refrain.\nA magical loop, a recursive song,\nIn the symphony of code, where brilliance belongs.", "refusal": null }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 39, "completion_tokens": 200, "total_tokens": 239, "prompt_tokens_details": { "cached_tokens": 0 }, "completion_tokens_details": { "reasoning_tokens": 0 } }, "system_fingerprint": null }
後でキーを置き換えるには、プロバイダーキーをローテーションするを参照してください。
パススルートークン
リクエストが EnterpriseAgentgatewayBackend に送信される前に、クライアントまたは成功した OpenID Connect (OIDC) 接続フローから既存のトークンを直接パススルーします。このオプションは、EnterpriseAgentgatewayBackend を作成する LLM プロバイダーにバックエンドクライアントがすでに認証済みになるよう、フェデレーション ID を設定している環境で役立ちます。現在、リクエストはトークンを Authorization ヘッダーに配置する必要があります。
クライアントが以下のように設定されていることを確認してください。
- EnterpriseAgentgatewayBackend にリクエストを送信するクライアントが、OIDC フローまたは API キーなどを通じて LLM プロバイダーに認証できること。
- 認証済みトークンまたは API キーが
Authorizationヘッダーを通じて EnterpriseAgentgatewayBackend へのリクエストで送信されること。
パススルー認証を使用するように EnterpriseAgentgatewayBackend を設定します。
kubectl apply -f- <<EOF apiVersion: enterpriseagentgateway.solo.io/v1alpha1 kind: EnterpriseAgentgatewayBackend metadata: name: openai namespace: agentgateway-system spec: ai: provider: openai: model: gpt-3.5-turbo policies: auth: passthrough: {} EOFこの設定を理解するために以下の表を確認してください。詳細については、API リファレンスを参照してください。
設定 説明 ai.provider.openaiOpenAI プロバイダーを定義します。 openai.model使用する OpenAI モデル( gpt-3.5-turboなど)。policies.authOpenAI API の認証トークンを設定します。例ではパススルー認証を使用しています。 EnterpriseAgentgatewayBackend への受信トラフィックをルーティングする HTTPRoute リソースを作成します。以下の例では、以前に作成した EnterpriseAgentgatewayBackend への
/openaiパスのルートをセットアップします。kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: openai namespace: agentgateway-system spec: parentRefs: - name: agentgateway-proxy namespace: agentgateway-system rules: - matches: - path: type: PathPrefix value: /openai backendRefs: - name: openai namespace: agentgateway-system group: enterpriseagentgateway.solo.io kind: EnterpriseAgentgatewayBackend EOF認証済みクライアントが EnterpriseAgentgatewayBackend にリクエストを送信するよう設定し、成功したレスポンスが返されることを確認します。たとえば、クライアントが AI Gateway を通じて curl リクエストを送信するように指示する場合があります。リクエストにはパススルー認証に必要な
Authorizationヘッダーが含まれていることに注意してください。EnterpriseAgentgatewayBackend でモデルを固定していない場合は、リクエストにモデルを含めます。curl "$INGRESS_GW_ADDRESS/openai" -H "Authorization: Bearer $TOKEN" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "Compose a poem that explains the concept of recursion in programming." } ] }'curl "localhost:8080/openai" -H "Authorization: Bearer $TOKEN" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "Compose a poem that explains the concept of recursion in programming." } ] }'出力例:
{ "id": "chatcmpl-AEHYs2B0XUlEioCduH1meERmMwBGF", "object": "chat.completion", "created": 1727967462, "model": "gpt-3.5-turbo-0125", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "In the world of code, a method elegant and rare,\nKnown as recursion, a loop beyond compare.\nLike a mirror reflecting its own reflection,\nIt calls upon itself with deep introspection.\n\nA function that calls itself with artful grace,\nDividing a problem into a smaller space.\nLike a nesting doll, layers deep and profound,\nIt solves complex tasks, looping around.\n\nWith each recursive call, a step is taken,\nTowards solving the problem, not forsaken.\nA dance of self-replication, a mesmerizing sight,\nUnraveling complexity with power and might.\n\nBut beware of infinite loops, a perilous dance,\nWithout a base case, it's a risky chance.\nFor recursion is a waltz with a delicate balance,\nInfinite beauty, yet a risky dalliance.\n\nSo embrace the concept, in programming's domain,\nLet recursion guide you, like a poetic refrain.\nA magical loop, a recursive song,\nIn the symphony of code, where brilliance belongs.", "refusal": null }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 39, "completion_tokens": 200, "total_tokens": 239, "prompt_tokens_details": { "cached_tokens": 0 }, "completion_tokens_details": { "reasoning_tokens": 0 } }, "system_fingerprint": null }
プロバイダーキーをローテーションする
プロバイダーが求める場合、漏洩が疑われる場合、または定期的な運用として、プロバイダーキーをローテーションします。Kubernetes Secret に保存したキーの場合は、クラスター内の Secret を更新します。仮想キーを使用するクライアント側の設定変更は不要です。
LLM プロバイダーのコンソールで新しい API キーを作成します。今は古いキーも有効なままにしておきます。
新しいキーを環境変数に保存します。
export NEW_OPENAI_API_KEY=<insert your new API key>EnterpriseAgentgatewayBackend が参照するシークレットを更新します。プロキシは再起動せずに新しいキーを取得します。
kubectl create secret generic openai-secret -n agentgateway-system \ --from-literal=Authorization="$NEW_OPENAI_API_KEY" \ --dry-run=client -o yaml | kubectl apply -f -プロキシ経由でリクエストを送信し、新しいキーで成功することを確認します。
curl "$INGRESS_GW_ADDRESS/openai" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}] }'curl "localhost:8080/openai" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}] }'出力例:
{ "choices": [{ "message": { "role": "assistant", "content": "Hello! How can I help you today?" } }] }LLM プロバイダーのコンソールで古いキーを取り消します。
代わりにキーをインラインで提供している場合は、EnterpriseAgentgatewayBackend の policies.auth.key フィールドを更新します。