View a markdown version of this page

获取 API 密钥 - 亚马逊基岩 AgentCore

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

获取 API 密钥

将 API 密钥存储在 AgentCore 身份库中后,您可以使用 AgentCore 软件开发工具包和@requires_api_key注解直接在代理中检索它们。例如,以下代码将从 “您的服务名称” API 密钥提供商处检索 API 密钥,以便您可以在函数中使用它。need_api_key

import asyncio from bedrock_agentcore.identity.auth import requires_api_key @requires_api_key( provider_name= "your-service-name" # replace with your own credential provider name ) async def need_api_key(*, api_key: str): # Use the API key pass # To invoke: # asyncio.run(need_api_key())