View a markdown version of this page

获取 API 密钥 - Amazon Bedrock AgentCore

获取 API 密钥

将 API 密钥存储在 AgentCore 身份保管库中后,即可使用 AgentCore SDK 和@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())