[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-aws-samples--bedrock-access-gateway":3,"tool-aws-samples--bedrock-access-gateway":64},[4,23,32,40,48,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":22},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,2,"2026-04-05T10:45:23",[13,14,15,16,17,18,19,20,21],"图像","数据工具","视频","插件","Agent","其他","语言模型","开发框架","音频","ready",{"id":24,"name":25,"github_repo":26,"description_zh":27,"stars":28,"difficulty_score":29,"last_commit_at":30,"category_tags":31,"status":22},2181,"OpenHands","OpenHands\u002FOpenHands","OpenHands 是一个专注于 AI 驱动开发的开源平台，旨在让智能体（Agent）像人类开发者一样理解、编写和调试代码。它解决了传统编程中重复性劳动多、环境配置复杂以及人机协作效率低等痛点，通过自动化流程显著提升开发速度。\n\n无论是希望提升编码效率的软件工程师、探索智能体技术的研究人员，还是需要快速原型验证的技术团队，都能从中受益。OpenHands 提供了灵活多样的使用方式：既可以通过命令行（CLI）或本地图形界面在个人电脑上轻松上手，体验类似 Devin 的流畅交互；也能利用其强大的 Python SDK 自定义智能体逻辑，甚至在云端大规模部署上千个智能体并行工作。\n\n其核心技术亮点在于模块化的软件智能体 SDK，这不仅构成了平台的引擎，还支持高度可组合的开发模式。此外，OpenHands 在 SWE-bench 基准测试中取得了 77.6% 的优异成绩，证明了其解决真实世界软件工程问题的能力。平台还具备完善的企业级功能，支持与 Slack、Jira 等工具集成，并提供细粒度的权限管理，适合从个人开发者到大型企业的各类用户场景。",70626,3,"2026-04-05T22:51:36",[19,17,20,16],{"id":33,"name":34,"github_repo":35,"description_zh":36,"stars":37,"difficulty_score":10,"last_commit_at":38,"category_tags":39,"status":22},3074,"gpt4free","xtekky\u002Fgpt4free","gpt4free 是一个由社区驱动的开源项目，旨在聚合多种可访问的大型语言模型（LLM）和媒体生成接口，让用户能更灵活、便捷地使用前沿 AI 能力。它解决了直接调用各类模型时面临的接口分散、门槛高或成本昂贵等痛点，通过统一的标准将不同提供商的资源整合在一起。\n\n无论是希望快速集成 AI 功能的开发者、需要多模型对比测试的研究人员，还是想免费体验最新技术的普通用户，都能从中受益。gpt4free 提供了丰富的使用方式：既包含易于上手的 Python 和 JavaScript 客户端库，也支持部署本地图形界面（GUI），更提供了兼容 OpenAI 标准的 REST API，方便无缝替换现有应用后端。\n\n其技术亮点在于强大的多提供商支持架构，能够动态调度包括 Opus、Gemini、DeepSeek 等多种主流模型资源，并支持 Docker 一键部署及本地推理。项目秉持社区优先原则，在降低使用门槛的同时，也为贡献者提供了扩展新接口的便利框架，是探索和利用多样化 AI 资源的实用工具。",65970,"2026-04-04T01:02:03",[16,19,17],{"id":41,"name":42,"github_repo":43,"description_zh":44,"stars":45,"difficulty_score":10,"last_commit_at":46,"category_tags":47,"status":22},51,"gstack","garrytan\u002Fgstack","gstack 是 Y Combinator CEO Garry Tan 亲自开源的一套 AI 工程化配置，旨在将 Claude Code 升级为你的虚拟工程团队。面对单人开发难以兼顾产品战略、架构设计、代码审查及质量测试的挑战，gstack 提供了一套标准化解决方案，帮助开发者实现堪比二十人团队的高效产出。\n\n这套配置特别适合希望提升交付效率的创始人、技术负责人，以及初次尝试 Claude Code 的开发者。gstack 的核心亮点在于内置了 15 个具有明确职责的 AI 角色工具，涵盖 CEO、设计师、工程经理、QA 等职能。用户只需通过简单的斜杠命令（如 `\u002Freview` 进行代码审查、`\u002Fqa` 执行测试、`\u002Fplan-ceo-review` 规划功能），即可自动化处理从需求分析到部署上线的全链路任务。\n\n所有操作基于 Markdown 和斜杠命令，无需复杂配置，完全免费且遵循 MIT 协议。gstack 不仅是一套工具集，更是一种现代化的软件工厂实践，让单人开发者也能拥有严谨的工程流程。",64604,"2026-04-05T23:10:16",[17,16],{"id":49,"name":50,"github_repo":51,"description_zh":52,"stars":53,"difficulty_score":10,"last_commit_at":54,"category_tags":55,"status":22},193,"meilisearch","meilisearch\u002Fmeilisearch","Meilisearch 是一个开源的极速搜索服务，专为现代应用和网站打造，开箱即用。它能帮助开发者快速集成高质量的搜索功能，无需复杂的配置或额外的数据预处理。传统搜索方案往往需要大量调优才能实现准确结果，而 Meilisearch 内置了拼写容错、同义词识别、即时响应等实用特性，并支持 AI 驱动的混合搜索（结合关键词与语义理解），显著提升用户查找信息的体验。\n\nMeilisearch 特别适合 Web 开发者、产品团队或初创公司使用，尤其适用于需要快速上线搜索功能的场景，如电商网站、内容平台或 SaaS 应用。它提供简洁的 RESTful API 和多种语言 SDK，部署简单，资源占用低，本地开发或生产环境均可轻松运行。对于希望在不依赖大型云服务的前提下，为用户提供流畅、智能搜索体验的团队来说，Meilisearch 是一个高效且友好的选择。",56972,"2026-04-05T22:34:33",[13,17,14,20,16,18],{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":22},4022,"awesome-claude-skills","ComposioHQ\u002Fawesome-claude-skills","awesome-claude-skills 是一个精心整理的开源资源库，旨在帮助用户挖掘和扩展 Claude AI 的潜力。它不仅仅是一份列表，更提供了实用的“技能（Skills）”模块，让 Claude 从单纯的文本生成助手，进化为能执行复杂工作流的智能代理。\n\n许多用户在使用 AI 时，常受限于其无法直接操作外部软件或处理特定格式文件的痛点。awesome-claude-skills 通过预设的工作流解决了这一问题：它不仅能教会 Claude 专业地处理 Word、PDF 等文档，进行代码开发与数据分析，还能借助 Composio 插件连接 Slack、邮箱及数百种常用应用，实现发送邮件、创建任务等自动化操作。这使得重复性任务变得标准化且可复用，极大提升了工作效率。\n\n无论是希望优化日常办公流程的普通用户、需要处理复杂文档的研究人员，还是寻求将 AI 深度集成到开发管线中的开发者，都能从中找到适合的解决方案。其独特的技术亮点在于“技能”的可定制性与强大的应用连接能力，让用户无需编写复杂代码，即可通过简单的配置让 Claude 具备跨平台执行真实任务的能力。如果你希望让 Claude",51312,"2026-04-05T19:04:23",[17,16],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":79,"owner_email":79,"owner_twitter":79,"owner_website":80,"owner_url":81,"languages":82,"stars":95,"forks":96,"last_commit_at":97,"license":98,"difficulty_score":10,"env_os":99,"env_gpu":100,"env_ram":101,"env_deps":102,"category_tags":112,"github_topics":113,"view_count":10,"oss_zip_url":79,"oss_zip_packed_at":79,"status":22,"created_at":120,"updated_at":121,"faqs":122,"releases":151},2580,"aws-samples\u002Fbedrock-access-gateway","bedrock-access-gateway","OpenAI-Compatible RESTful APIs for Amazon Bedrock","bedrock-access-gateway 是一个开源桥梁，旨在让开发者能够直接使用 OpenAI 格式的 API 来调用亚马逊 Bedrock 上的各类大模型。它主要解决了应用迁移与测试中的兼容性问题：如果你已有的项目是基于 OpenAI SDK 构建的，无需修改任何代码，即可通过此网关无缝切换至 Bedrock 提供的丰富模型资源进行实验或部署。\n\n这款工具非常适合正在开发生成式 AI 应用的工程师、希望评估不同模型能力的研究人员，以及需要在 AutoGen 等框架中快速集成多模型支持的技术团队。其核心亮点在于全面兼容 OpenAI 标准接口，不仅支持聊天补全、工具调用、嵌入和多模态处理，还特别优化了流式响应体验。最新升级更原生支持 Amazon API Gateway 的流式传输，显著降低了延迟并优化了成本。此外，它还率先支持了包括 Claude 4.5 系列、Amazon Nova、DeepSeek-R1 及通义千问等前沿模型的推理能力，甚至涵盖了思维链（Reasoning）和交错思考等高级特性，让用户能轻松探索最顶尖的 AI 能力。","# Bedrock Access Gateway\n\nOpenAI-compatible RESTful APIs for Amazon Bedrock\n\n## What's New 🔥\n\n**API Gateway Response Streaming Support** - You can now deploy with Amazon API Gateway REST API instead of ALB, enabling true response streaming for better latency and cost optimization. See [Deployment Options](#deployment-options) for details.\n\n**Latest Models Supported:**\n- **Claude 4.5 Family**: Opus 4.5, Sonnet 4.5, Haiku 4.5 - Anthropic's most intelligent models with enhanced coding and agent capabilities\n- **Amazon Nova**: Nova Micro, Nova Lite, Nova Pro, Nova Premier - Amazon's native foundation models with multimodal support\n- **DeepSeek**: DeepSeek-R1 (reasoning), DeepSeek-V3.1 - Advanced reasoning and general-purpose models\n- **Qwen 3**: Qwen3-32B, Qwen3-235B, Qwen3-Coder-30B, Qwen3-Coder-480B - Alibaba's latest language and coding models\n- **OpenAI OSS**: gpt-oss-20b, gpt-oss-120b - Open-source GPT models available via Bedrock\n\nIt also supports reasoning for **Claude 4\u002F4.5** (extended thinking and interleaved thinking) and **DeepSeek R1**. Check [How to Use](.\u002Fdocs\u002FUsage.md#reasoning) for more details. You need to first run the Models API to refresh the model list.\n\n## Overview\n\nAmazon Bedrock offers a wide range of foundation models (such as Claude 3 Opus\u002FSonnet\u002FHaiku, Llama 2\u002F3, Mistral\u002FMixtral,\netc.) and a broad set of capabilities for you to build generative AI applications. Check the [Amazon Bedrock](https:\u002F\u002Faws.amazon.com\u002Fbedrock) landing page for additional information.\n\nSometimes, you might have applications developed using OpenAI APIs or SDKs, and you want to experiment with Amazon Bedrock without modifying your codebase. Or you may simply wish to evaluate the capabilities of these foundation models in tools like AutoGen etc. Well, this repository allows you to access Amazon Bedrock models seamlessly through OpenAI APIs and SDKs, enabling you to test these models without code changes.\n\nIf you find this GitHub repository useful, please consider giving it a free star ⭐ to show your appreciation and support for the project.\n\n**Features:**\n\n- [x] Support streaming response via server-sent events (SSE)\n- [x] Support Model APIs\n- [x] Support Chat Completion APIs\n- [x] Support Tool Call\n- [x] Support Embedding API\n- [x] Support Multimodal API\n- [x] Support Cross-Region Inference\n- [x] Support Application Inference Profiles (**new**)\n- [x] Support Reasoning (**new**)\n- [x] Support Interleaved thinking (**new**)\n- [x] Support Prompt Caching (**new**)\n\nPlease check [Usage Guide](.\u002Fdocs\u002FUsage.md) for more details about how to use the new APIs.\n\n\n## Get Started\n\n### Prerequisites\n\nPlease make sure you have met below prerequisites:\n\n- Access to Amazon Bedrock foundation models.\n\n> For more information on how to request model access, please refer to the [Amazon Bedrock User Guide](https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Fmodel-access.html) (Set Up > Model access)\n\n### Architecture\n\nThe following diagram illustrates the reference architecture. It uses [Amazon API Gateway response streaming](https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fbuilding-responsive-apis-with-amazon-api-gateway-response-streaming\u002F) with Lambda for SSE support.\n\n![Architecture](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Faws-samples_bedrock-access-gateway_readme_72d443532031.png)\n\n### Deployment Options\n\n| Option | Pros | Cons | Best For |\n|--------|------|------|----------|\n| **API Gateway + Lambda** | No VPC required, pay-per-request, native streaming support, lower operational overhead | Potential cold starts | Most use cases, cost-sensitive deployments |\n| **ALB + Fargate** | Lowest streaming latency, no cold starts | Higher cost, requires VPC | High-throughput, latency-sensitive workloads |\n\nYou can also use Lambda Function URL as an alternative, see [example](https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter\u002Ftree\u002Fmain\u002Fexamples\u002Ffastapi-response-streaming)\n\n### Deployment\n\nPlease follow the steps below to deploy the Bedrock Proxy APIs into your AWS account. Only supports regions where Amazon Bedrock is available (such as `us-west-2`). The deployment will take approximately **10-15 minutes** 🕒.\n\n**Step 1: Create your own API key in Secrets Manager (MUST)**\n\n> **Note:** This step is to use any string (without spaces) you like to create a custom API Key (credential) that will be used to access the proxy API later. This key does not have to match your actual OpenAI key, and you don't need to have an OpenAI API key. please keep the key safe and private.\n\n1. Open the AWS Management Console and navigate to the AWS Secrets Manager service.\n2. Click on \"Store a new secret\" button.\n3. In the \"Choose secret type\" page, select:\n\n   Secret type: Other type of secret\n   Key\u002Fvalue pairs:\n   - Key: api_key\n   - Value: Enter your API key value\n\n   Click \"Next\"\n4. In the \"Configure secret\" page:\n   Secret name: Enter a name (e.g., \"BedrockProxyAPIKey\")\n   Description: (Optional) Add a description of your secret\n5. Click \"Next\" and review all your settings and click \"Store\"\n\nAfter creation, you'll see your secret in the Secrets Manager console. Make note of the secret ARN.\n\n**Step 2: Build and push container images to ECR**\n\n1. Clone this repository:\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway.git\n   cd bedrock-access-gateway\n   ```\n\n2. Run the build and push script:\n   ```bash\n   cd scripts\n   bash .\u002Fpush-to-ecr.sh\n   ```\n\n3. Follow the prompts to configure:\n   - ECR repository names (or use defaults)\n   - Image tag (or use default: `latest`)\n   - AWS region (or use default: `us-east-1`)\n\n4. The script will build and push both Lambda and ECS\u002FFargate images to your ECR repositories.\n\n5. **Important**: Copy the image URIs displayed at the end of the script output. You'll need these in the next step.\n\n**Step 3: Deploy the CloudFormation stack**\n\n1. Download the CloudFormation template you want to use:\n   - For API Gateway + Lambda: [`deployment\u002FBedrockProxy.template`](deployment\u002FBedrockProxy.template)\n   - For ALB + Fargate: [`deployment\u002FBedrockProxyFargate.template`](deployment\u002FBedrockProxyFargate.template)\n\n2. Sign in to AWS Management Console and navigate to the CloudFormation service in your target region.\n\n3. Click \"Create stack\" → \"With new resources (standard)\".\n\n4. Upload the template file you downloaded.\n\n5. On the \"Specify stack details\" page, provide the following information:\n   - **Stack name**: Enter a stack name (e.g., \"BedrockProxyAPI\")\n   - **ApiKeySecretArn**: Enter the secret ARN from Step 1\n   - **ContainerImageUri**: Enter the ECR image URI from Step 2 output\n   - **DefaultModelId**: (Optional) Change the default model if needed\n\n   Click \"Next\".\n\n6. On the \"Configure stack options\" page, you can leave the default settings or customize them according to your needs. Click \"Next\".\n\n7. On the \"Review\" page, review all details. Check the \"I acknowledge that AWS CloudFormation might create IAM resources\" checkbox at the bottom. Click \"Submit\".\n\nThat is it! 🎉 Once deployed, click the CloudFormation stack and go to **Outputs** tab, you can find the API Base URL from `APIBaseUrl`, the value should look like `http:\u002F\u002Fxxxx.xxx.elb.amazonaws.com\u002Fapi\u002Fv1`.\n\n### Troubleshooting\n\nIf you encounter any issues, please check the [Troubleshooting Guide](.\u002Fdocs\u002FTroubleshooting.md) for more details.\n\n### SDK\u002FAPI Usage\n\nAll you need is the API Key and the API Base URL. If you didn't set up your own key following Step 1, the application will fail to start with an error message indicating that the API Key is not configured.\n\nNow, you can try out the proxy APIs. Let's say you want to test Claude 3 Sonnet model (model ID: `anthropic.claude-3-sonnet-20240229-v1:0`)...\n\n**Example API Usage**\n\n```bash\nexport OPENAI_API_KEY=\u003CAPI key>\nexport OPENAI_BASE_URL=\u003CAPI base url>\n# For older versions\n# https:\u002F\u002Fgithub.com\u002Fopenai\u002Fopenai-python\u002Fissues\u002F624\nexport OPENAI_API_BASE=\u003CAPI base url>\n```\n\n```bash\ncurl $OPENAI_BASE_URL\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n    \"model\": \"anthropic.claude-3-sonnet-20240229-v1:0\",\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Hello!\"\n      }\n    ]\n  }'\n```\n\n**Example SDK Usage**\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\ncompletion = client.chat.completions.create(\n    model=\"anthropic.claude-3-sonnet-20240229-v1:0\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n)\n\nprint(completion.choices[0].message.content)\n```\n\nPlease check [Usage Guide](.\u002Fdocs\u002FUsage.md) for more details about how to use embedding API, multimodal API and tool call.\n\n### Application Inference Profiles\n\nThis proxy now supports **Application Inference Profiles**, which allow you to track usage and costs for your model invocations. You can use application inference profiles created in your AWS account for cost tracking and monitoring purposes.\n\n**Using Application Inference Profiles:**\n\n```bash\n# Use an application inference profile ARN as the model ID\ncurl $OPENAI_BASE_URL\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n    \"model\": \"arn:aws:bedrock:us-west-2:123456789012:application-inference-profile\u002Fyour-profile-id\",\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Hello!\"\n      }\n    ]\n  }'\n```\n\n**SDK Usage with Application Inference Profiles:**\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\ncompletion = client.chat.completions.create(\n    model=\"arn:aws:bedrock:us-west-2:123456789012:application-inference-profile\u002Fyour-profile-id\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n)\n\nprint(completion.choices[0].message.content)\n```\n\n**Benefits of Application Inference Profiles:**\n- **Cost Tracking**: Track usage and costs for specific applications or use cases\n- **Usage Monitoring**: Monitor model invocation metrics through CloudWatch\n- **Tag-based Cost Allocation**: Use AWS cost allocation tags for detailed billing analysis\n\nFor more information about creating and managing application inference profiles, see the [Amazon Bedrock User Guide](https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Finference-profiles-create.html).\n\n### Prompt Caching\n\nThis proxy now supports **Prompt Caching** for Claude and Nova models, which can reduce costs by up to 90% and latency by up to 85% for workloads with repeated prompts.\n\n**Supported Models:**\n- Claude models (Claude 3.5 Haiku, Claude 4, Claude 4.5, etc.)\n- Nova models (Nova Micro, Nova Lite, Nova Pro, Nova Premier)\n\n**Enabling Prompt Caching:**\n\nYou can enable prompt caching in two ways:\n\n1. **Globally via Environment Variable** (set in ECS Task Definition or Lambda):\n```bash\nENABLE_PROMPT_CACHING=true\n```\n\n2. **Per-request via `extra_body`** :\n\n**Python SDK:**\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\n\n# Cache system prompts\nresponse = client.chat.completions.create(\n    model=\"global.anthropic.claude-haiku-4-5-20251001-v1:0\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are an expert assistant with knowledge of...\"},\n        {\"role\": \"user\", \"content\": \"Help me with this task\"}\n    ],\n    extra_body={\n        \"prompt_caching\": {\"system\": True}\n    }\n)\n\n# Check cache hit\nif response.usage.prompt_tokens_details:\n    cached_tokens = response.usage.prompt_tokens_details.cached_tokens\n    print(f\"Cached tokens: {cached_tokens}\")\n```\n\n**cURL:**\n```bash\ncurl $OPENAI_BASE_URL\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n    \"model\": \"global.anthropic.claude-haiku-4-5-20251001-v1:0\",\n    \"messages\": [\n      {\"role\": \"system\", \"content\": \"Long system prompt...\"},\n      {\"role\": \"user\", \"content\": \"Question\"}\n    ],\n    \"extra_body\": {\n      \"prompt_caching\": {\"system\": true}\n    }\n  }'\n```\n\n**Cache Options:**\n- `\"prompt_caching\": {\"system\": true}` - Cache system prompts\n- `\"prompt_caching\": {\"messages\": true}` - Cache user messages\n- `\"prompt_caching\": {\"system\": true, \"messages\": true}` - Cache both\n\n**Requirements:**\n- Prompt must be ≥1,024 tokens to enable caching\n- Cache TTL is 5 minutes (resets on each cache hit)\n- Nova models have a 20,000 token caching limit\n\nFor more information, see the [Amazon Bedrock Prompt Caching Guide](https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Fprompt-caching.html).\n\n## Other Examples\n\n### LangChain\n\nMake sure you use `ChatOpenAI(...)` instead of `OpenAI(...)`\n\n```python\n# pip install langchain-openai\nimport os\n\nfrom langchain.chains import LLMChain\nfrom langchain.prompts import PromptTemplate\nfrom langchain_openai import ChatOpenAI\n\nchat = ChatOpenAI(\n    model=\"anthropic.claude-3-sonnet-20240229-v1:0\",\n    temperature=0,\n    openai_api_key=os.environ['OPENAI_API_KEY'],\n    openai_api_base=os.environ['OPENAI_BASE_URL'],\n)\n\ntemplate = \"\"\"Question: {question}\n\nAnswer: Let's think step by step.\"\"\"\n\nprompt = PromptTemplate.from_template(template)\nllm_chain = LLMChain(prompt=prompt, llm=chat)\n\nquestion = \"What NFL team won the Super Bowl in the year Justin Beiber was born?\"\nresponse = llm_chain.invoke(question)\nprint(response)\n\n```\n\n## FAQs\n\n### About Privacy\n\nThis application does not collect any of your data. Furthermore, it does not log any requests or responses by default.\n\n### Why choose API Gateway vs ALB?\n\n**API Gateway + Lambda** uses [API Gateway response streaming](https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fbuilding-responsive-apis-with-amazon-api-gateway-response-streaming\u002F) with [Lambda Web Adapter](https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter) to support SSE streaming without requiring a VPC. This is a cost-effective, serverless option with up to 10 minutes timeout.\n\n**ALB + Fargate** provides the lowest streaming latency with no cold starts, ideal for high-throughput workloads.\n\n### Which regions are supported?\n\nGenerally speaking, all regions that Amazon Bedrock supports will also be supported, if not, please raise an issue in Github.\n\nNote that not all models are available in those regions.\n\n### Which models are supported?\n\nYou can use the [Models API](.\u002Fdocs\u002FUsage.md#models-api) to get\u002Frefresh a list of supported models in the current region.\n\n### Can I run this locally\n\nYes, you can run this locally, e.g. run below command under `src` folder:\n\n```bash\nuvicorn api.app:app --host 0.0.0.0 --port 8000\n```\n\nThe API base url should look like `http:\u002F\u002Flocalhost:8000\u002Fapi\u002Fv1`.\n\n### Any performance sacrifice or latency increase by using the proxy APIs\n\nCompared with direct AWS SDK calls, the proxy architecture will add some latency. The default API Gateway + Lambda deployment provides good streaming performance with Lambda response streaming.\n\nFor lowest latency on streaming responses, consider the ALB + Fargate deployment option which eliminates cold starts and provides consistent performance.\n\n### Any plan to support SageMaker models?\n\nCurrently, there is no plan to support SageMaker models. This may change provided there's a demand from customers.\n\n### Any plan to support Bedrock custom models?\n\nFine-tuned models and models with Provisioned Throughput are currently not supported. You can clone the repo and make the customization if needed.\n\n### How to upgrade?\n\nTo use the latest features, you need follow the deployment guide to redeploy the application. You can upgrade the existing CloudFormation stack to get the latest changes.\n\n## Security\n\nSee [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.\n\n## License\n\nThis library is licensed under the MIT-0 License. See the LICENSE file.\n","# 床岩访问网关\n\n适用于亚马逊 Bedrock 的 OpenAI 兼容 RESTful API\n\n## 最新动态 🔥\n\n**API 网关响应流式传输支持** - 您现在可以使用 Amazon API 网关 REST API 而不是 ALB 进行部署，从而实现真正的响应流式传输，以获得更低的延迟并优化成本。有关详细信息，请参阅[部署选项](#deployment-options)。\n\n**最新支持的模型：**\n- **Claude 4.5 系列**：Opus 4.5、Sonnet 4.5、Haiku 4.5 - Anthropic 最智能的模型，具备增强的编码和代理能力\n- **Amazon Nova**：Nova Micro、Nova Lite、Nova Pro、Nova Premier - Amazon 原生的基础模型，支持多模态\n- **DeepSeek**：DeepSeek-R1（推理）、DeepSeek-V3.1 - 先进的推理和通用模型\n- **通义千问 3**：Qwen3-32B、Qwen3-235B、Qwen3-Coder-30B、Qwen3-Coder-480B - 阿里巴巴最新的语言和编码模型\n- **OpenAI 开源模型**：gpt-oss-20b、gpt-oss-120b - 可通过 Bedrock 使用的开源 GPT 模型\n\n它还支持 **Claude 4\u002F4.5**（扩展思维和交错思维）以及 **DeepSeek R1** 的推理功能。更多详情请参阅[使用方法](.\u002Fdocs\u002FUsage.md#reasoning)。您需要先运行 Models API 来刷新模型列表。\n\n## 概述\n\n亚马逊 Bedrock 提供了广泛的基础模型（如 Claude 3 Opus\u002FSonnet\u002FHaiku、Llama 2\u002F3、Mistral\u002FMixtral 等）以及丰富的功能，帮助您构建生成式 AI 应用程序。有关更多信息，请访问 [亚马逊 Bedrock](https:\u002F\u002Faws.amazon.com\u002Fbedrock) 官方页面。\n\n有时，您可能已经使用 OpenAI 的 API 或 SDK 开发了应用程序，并希望在不修改代码库的情况下尝试亚马逊 Bedrock。或者您只是想在 AutoGen 等工具中评估这些基础模型的能力。那么，这个仓库可以让您通过 OpenAI 的 API 和 SDK 无缝访问亚马逊 Bedrock 的模型，从而无需更改代码即可测试这些模型。\n\n如果您觉得这个 GitHub 仓库很有用，请考虑免费给它点个星 ⭐，以表达您对该项目的支持与感谢。\n\n**功能特性：**\n\n- [x] 支持通过服务器发送事件 (SSE) 进行流式响应\n- [x] 支持 Models API\n- [x] 支持 Chat Completion API\n- [x] 支持工具调用\n- [x] 支持 Embedding API\n- [x] 支持 Multimodal API\n- [x] 支持跨区域推理\n- [x] 支持应用推理配置文件（新）\n- [x] 支持推理（新）\n- [x] 支持交错思维（新）\n- [x] 支持提示缓存（新）\n\n有关如何使用新 API 的更多详细信息，请查看[使用指南](.\u002Fdocs\u002FUsage.md)。\n\n\n## 开始使用\n\n### 前提条件\n\n请确保您已满足以下前提条件：\n\n- 拥有亚马逊 Bedrock 基础模型的访问权限。\n\n> 有关如何申请模型访问权限的更多信息，请参阅 [亚马逊 Bedrock 用户指南](https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Fmodel-access.html)（设置 > 模型访问）\n\n### 架构\n\n下图展示了参考架构。它使用 [Amazon API 网关响应流式传输](https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fbuilding-responsive-apis-with-amazon-api-gateway-response-streaming\u002F) 结合 Lambda 实现 SSE 支持。\n\n![架构](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Faws-samples_bedrock-access-gateway_readme_72d443532031.png)\n\n### 部署选项\n\n| 选项 | 优点 | 缺点 | 适用场景 |\n|--------|------|------|----------|\n| **API 网关 + Lambda** | 无需 VPC，按需付费，原生流式支持，较低的运维开销 | 可能存在冷启动 | 多数用例，成本敏感型部署 |\n| **ALB + Fargate** | 流式传输延迟最低，无冷启动 | 成本较高，需要 VPC | 高吞吐量、对延迟敏感的工作负载 |\n\n您也可以使用 Lambda 函数 URL 作为替代方案，详见[示例](https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter\u002Ftree\u002Fmain\u002Fexamples\u002Ffastapi-response-streaming)\n\n### 部署\n\n请按照以下步骤将 Bedrock 代理 API 部署到您的 AWS 账户中。仅支持 Amazon Bedrock 可用的区域（例如 `us-west-2`）。部署大约需要 **10–15 分钟** 🕒。\n\n**步骤 1：在 Secrets Manager 中创建您自己的 API 密钥（必须）**\n\n> **注意**：此步骤是为了使用任意不含空格的字符串创建一个自定义 API 密钥（凭据），该密钥将在后续用于访问代理 API。此密钥无需与您的实际 OpenAI 密钥匹配，您也不需要拥有 OpenAI API 密钥。请务必妥善保管并确保密钥的私密性。\n\n1. 打开 AWS 管理控制台，导航至 AWS Secrets Manager 服务。\n2. 单击“存储新密钥”按钮。\n3. 在“选择密钥类型”页面中，选择：\n\n   密钥类型：其他类型的密钥  \n   键\u002F值对：\n   - 键：api_key\n   - 值：输入您的 API 密钥值\n\n   单击“下一步”\n4. 在“配置密钥”页面中：\n   密钥名称：输入一个名称（例如“BedrockProxyAPIKey”）\n   描述：（可选）添加关于此密钥的描述\n5. 单击“下一步”，检查所有设置并单击“存储”。\n\n创建完成后，您将在 Secrets Manager 控制台中看到您的密钥。请记下密钥的 ARN。\n\n**步骤 2：构建并推送容器镜像至 ECR**\n\n1. 克隆此仓库：\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway.git\n   cd bedrock-access-gateway\n   ```\n\n2. 运行构建和推送脚本：\n   ```bash\n   cd scripts\n   bash .\u002Fpush-to-ecr.sh\n   ```\n\n3. 按照提示进行配置：\n   - ECR 存储库名称（或使用默认值）\n   - 镜像标签（或使用默认值：`latest`）\n   - AWS 区域（或使用默认值：`us-east-1`）\n\n4. 脚本将构建并分别将 Lambda 和 ECS\u002FFargate 的镜像推送到您的 ECR 存储库中。\n\n5. **重要提示**：请复制脚本输出末尾显示的镜像 URI。您将在下一步中用到这些 URI。\n\n**步骤 3：部署 CloudFormation 堆栈**\n\n1. 下载您想要使用的 CloudFormation 模板：\n   - 对于 API Gateway + Lambda：[`deployment\u002FBedrockProxy.template`](deployment\u002FBedrockProxy.template)\n   - 对于 ALB + Fargate：[`deployment\u002FBedrockProxyFargate.template`](deployment\u002FBedrockProxyFargate.template)\n\n2. 登录 AWS 管理控制台，在目标区域导航至 CloudFormation 服务。\n3. 单击“创建堆栈”→“使用新资源（标准）”。\n4. 上传您下载的模板文件。\n5. 在“指定堆栈详细信息”页面中，提供以下信息：\n   - **堆栈名称**：输入一个堆栈名称（例如“BedrockProxyAPI”）\n   - **ApiKeySecretArn**：输入步骤 1 中获得的密钥 ARN\n   - **ContainerImageUri**：输入步骤 2 输出中的 ECR 镜像 URI\n   - **DefaultModelId**：（可选）根据需要更改默认模型\n\n   单击“下一步”。\n6. 在“配置堆栈选项”页面中，您可以保留默认设置，也可以根据需求进行自定义。单击“下一步”。\n7. 在“审核”页面中，仔细检查所有详细信息。勾选底部的“我确认 AWS CloudFormation 可能会创建 IAM 资源”复选框。单击“提交”。\n\n就完成了！🎉 部署完成后，单击 CloudFormation 堆栈并进入 **Outputs** 选项卡，您可以在 `APIBaseUrl` 中找到 API 基础 URL，其值应类似于 `http:\u002F\u002Fxxxx.xxx.elb.amazonaws.com\u002Fapi\u002Fv1`。\n\n### 故障排除\n\n如果您遇到任何问题，请查看 [故障排除指南](.\u002Fdocs\u002FTroubleshooting.md) 以获取更多详细信息。\n\n### SDK\u002FAPI 使用\n\n您只需要 API 密钥和 API 基础 URL 即可。如果您未按照步骤 1 设置自己的密钥，则应用程序将无法启动，并会显示一条错误消息，指出未配置 API 密钥。\n\n现在，您可以试用代理 API。假设您想测试 Claude 3 Sonnet 模型（模型 ID：`anthropic.claude-3-sonnet-20240229-v1:0`）……\n\n**API 使用示例**\n\n```bash\nexport OPENAI_API_KEY=\u003CAPI 密钥>\nexport OPENAI_BASE_URL=\u003CAPI 基础 URL>\n# 对于旧版本\n# https:\u002F\u002Fgithub.com\u002Fopenai\u002Fopenai-python\u002Fissues\u002F624\nexport OPENAI_API_BASE=\u003CAPI 基础 URL>\n```\n\n```bash\ncurl $OPENAI_BASE_URL\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n    \"model\": \"anthropic.claude-3-sonnet-20240229-v1:0\",\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Hello!\"\n      }\n    ]\n  }'\n```\n\n**SDK 使用示例**\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\ncompletion = client.chat.completions.create(\n    model=\"anthropic.claude-3-sonnet-20240229-v1:0\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n)\n\nprint(completion.choices[0].message.content)\n```\n\n有关如何使用嵌入 API、多模态 API 和工具调用的更多详细信息，请参阅 [使用指南](.\u002Fdocs\u002FUsage.md)。\n\n### 应用推理配置文件\n\n此代理现支持 **应用推理配置文件**，允许您跟踪模型调用的使用情况和成本。您可以使用在 AWS 账户中创建的应用推理配置文件来进行成本跟踪和监控。\n\n**使用应用推理配置文件：**\n\n```bash\n# 将应用推理配置文件 ARN 用作模型 ID\ncurl $OPENAI_BASE_URL\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n    \"model\": \"arn:aws:bedrock:us-west-2:123456789012:application-inference-profile\u002Fyour-profile-id\",\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Hello!\"\n      }\n    ]\n  }'\n```\n\n**使用应用推理配置文件的 SDK 示例：**\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\ncompletion = client.chat.completions.create(\n    model=\"arn:aws:bedrock:us-west-2:123456789012:application-inference-profile\u002Fyour-profile-id\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n)\n\nprint(completion.choices[0].message.content)\n```\n\n**应用推理配置文件的优势：**\n- **成本跟踪**：跟踪特定应用或用例的使用情况和成本\n- **使用监控**：通过 CloudWatch 监控模型调用指标\n- **基于标签的成本分配**：使用 AWS 成本分配标签进行详细的账单分析\n\n有关创建和管理应用推理配置文件的更多信息，请参阅 [Amazon Bedrock 用户指南](https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Finference-profiles-create.html)。\n\n### 提示缓存\n\n此代理现支持 Claude 和 Nova 模型的 **提示缓存**，对于具有重复提示的工作负载，提示缓存可以将成本降低多达 90%，并将延迟降低多达 85%。\n\n**支持的模型：**\n- Claude 模型（Claude 3.5 Haiku、Claude 4、Claude 4.5 等）\n- Nova 模型（Nova Micro、Nova Lite、Nova Pro、Nova Premier）\n\n**启用提示缓存的方法：**\n\n您可以通过两种方式启用提示缓存：\n\n1. **通过环境变量全局启用**（在 ECS 任务定义或 Lambda 中设置）：\n```bash\nENABLE_PROMPT_CACHING=true\n```\n\n2. **通过 `extra_body` 进行每请求配置**：\n\n**Python SDK 示例：**\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\n\n# 缓存系统提示\nresponse = client.chat.completions.create(\n    model=\"global.anthropic.claude-haiku-4-5-20251001-v1:0\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"你是一位在…方面具有专业知识的专家助手\"},\n        {\"role\": \"user\", \"content\": \"帮我完成这项任务\"}\n    ],\n    extra_body={\n        \"prompt_caching\": {\"system\": True}\n    }\n)\n\n# 检查缓存命中情况\nif response.usage.prompt_tokens_details:\n    cached_tokens = response.usage.prompt_tokens_details.cached_tokens\n    print(f\"缓存的 token 数量：{cached_tokens}\")\n```\n\n**cURL:**\n```bash\ncurl $OPENAI_BASE_URL\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n    \"model\": \"global.anthropic.claude-haiku-4-5-20251001-v1:0\",\n    \"messages\": [\n      {\"role\": \"system\", \"content\": \"长篇系统提示...\"},\n      {\"role\": \"user\", \"content\": \"问题\"}\n    ],\n    \"extra_body\": {\n      \"prompt_caching\": {\"system\": true}\n    }\n  }'\n```\n\n**缓存选项：**\n- `\"prompt_caching\": {\"system\": true}` - 缓存系统提示\n- `\"prompt_caching\": {\"messages\": true}` - 缓存用户消息\n- `\"prompt_caching\": {\"system\": true, \"messages\": true}` - 同时缓存系统提示和用户消息\n\n**要求：**\n- 提示必须至少包含 1,024 个 token 才能启用缓存\n- 缓存的 TTL 为 5 分钟（每次缓存命中都会重置）\n- Nova 系列模型的缓存上限为 20,000 个 token\n\n更多信息请参阅 [Amazon Bedrock 提示缓存指南](https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Fprompt-caching.html)。\n\n## 其他示例\n\n### LangChain\n\n请确保使用 `ChatOpenAI(...)` 而不是 `OpenAI(...)`\n\n```python\n# 安装 langchain-openai\nimport os\n\nfrom langchain.chains import LLMChain\nfrom langchain.prompts import PromptTemplate\nfrom langchain_openai import ChatOpenAI\n\nchat = ChatOpenAI(\n    model=\"anthropic.claude-3-sonnet-20240229-v1:0\",\n    temperature=0,\n    openai_api_key=os.environ['OPENAI_API_KEY'],\n    openai_api_base=os.environ['OPENAI_BASE_URL'],\n)\n\ntemplate = \"\"\"问题：{question}\n\n答案：让我们一步步思考。\"\"\"\n\nprompt = PromptTemplate.from_template(template)\nllm_chain = LLMChain(prompt=prompt, llm=chat)\n\nquestion = \"贾斯汀·比伯出生那年，哪支球队赢得了超级碗？\"\nresponse = llm_chain.invoke(question)\nprint(response)\n\n```\n\n## 常见问题解答\n\n### 关于隐私\n\n本应用不会收集您的任何数据。此外，默认情况下也不会记录任何请求或响应。\n\n### 为什么选择 API Gateway 而不是 ALB？\n\n**API Gateway + Lambda** 使用 [API Gateway 响应流式传输](https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fbuilding-responsive-apis-with-amazon-api-gateway-response-streaming\u002F) 结合 [Lambda Web Adapter](https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter)，可在无需 VPC 的情况下支持 SSE 流式传输。这是一种经济高效的无服务器方案，超时时间最长可达 10 分钟。\n\n**ALB + Fargate** 则提供最低的流式传输延迟且无冷启动问题，非常适合高吞吐量的工作负载。\n\n### 支持哪些区域？\n\n一般来说，所有 Amazon Bedrock 支持的区域都适用；如果未涵盖，请在 Github 上提交问题。请注意，并非所有模型在这些区域都可用。\n\n### 支持哪些模型？\n\n您可以使用 [Models API](.\u002Fdocs\u002FUsage.md#models-api) 获取或刷新当前区域支持的模型列表。\n\n### 是否可以在本地运行？\n\n是的，您可以在本地运行，例如在 `src` 文件夹下执行以下命令：\n\n```bash\nuvicorn api.app:app --host 0.0.0.0 --port 8000\n```\n\n此时 API 的基础 URL 应为 `http:\u002F\u002Flocalhost:8000\u002Fapi\u002Fv1`。\n\n### 使用代理 API 是否会牺牲性能或增加延迟？\n\n与直接调用 AWS SDK 相比，代理架构会引入一定的延迟。默认的 API Gateway + Lambda 部署通过 Lambda 响应流式传输，能够提供良好的流式传输性能。若希望获得最低的流式响应延迟，建议采用 ALB + Fargate 部署方案，该方案可消除冷启动并提供一致的性能。\n\n### 是否计划支持 SageMaker 模型？\n\n目前暂无支持 SageMaker 模型的计划。不过，若客户有需求，未来可能会考虑添加此功能。\n\n### 是否计划支持 Bedrock 自定义模型？\n\n目前不支持微调模型或具有预置吞吐量的模型。如果您有定制需求，可以克隆仓库自行实现。\n\n### 如何升级？\n\n要使用最新功能，您需要按照部署指南重新部署应用程序。可以通过升级现有的 CloudFormation 堆栈来获取最新更改。\n\n## 安全性\n\n更多信息请参阅 [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications)。\n\n## 许可证\n\n本库采用 MIT-0 许可证授权。详情请参阅 LICENSE 文件。","# Bedrock Access Gateway 快速上手指南\n\nBedrock Access Gateway 是一个开源工具，旨在通过 OpenAI 兼容的 RESTful API 接口访问 Amazon Bedrock 上的各类大模型（如 Claude、Llama、Nova 等）。它允许你在不修改现有代码的情况下，将基于 OpenAI SDK 的应用无缝迁移至 Amazon Bedrock。\n\n## 环境准备\n\n在开始部署前，请确保满足以下前置条件：\n\n1.  **AWS 账号权限**：\n    *   拥有访问 Amazon Bedrock 基础模型的权限。\n    *   若未开通模型访问，请参考 [Amazon Bedrock 用户指南](https:\u002F\u002Fdocs.aws.amazon.com\u002Fbedrock\u002Flatest\u002Fuserguide\u002Fmodel-access.html) 进行申请。\n2.  **本地工具链**：\n    *   已安装并配置好 AWS CLI (`aws configure`)。\n    *   已安装 Docker（用于构建容器镜像）。\n    *   已安装 Git。\n3.  **区域限制**：\n    *   部署需在支持 Amazon Bedrock 的区域进行（例如 `us-west-2`）。\n\n## 安装步骤\n\n部署过程大约需要 **10-15 分钟**，主要包含创建密钥、构建镜像和部署云资源三个步骤。\n\n### 第一步：创建 API 密钥 (Secrets Manager)\n\n你需要创建一个自定义 API Key 用于后续访问代理接口（无需真实的 OpenAI Key）。\n\n1.  登录 AWS 控制台，进入 **Secrets Manager** 服务。\n2.  点击 **\"Store a new secret\"**。\n3.  选择 **\"Other type of secret\"**，添加键值对：\n    *   Key: `api_key`\n    *   Value: `\u003C输入你自定义的任意字符串，不含空格>`\n4.  命名密钥（例如 `BedrockProxyAPIKey`），完成创建。\n5.  **重要**：记录生成的 **Secret ARN**。\n\n### 第二步：构建并推送容器镜像\n\n克隆仓库并将镜像推送到你的 Amazon ECR。\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway.git\ncd bedrock-access-gateway\u002Fscripts\nbash .\u002Fpush-to-ecr.sh\n```\n\n*   按提示确认 ECR 仓库名称、镜像标签（默认 `latest`）和 AWS 区域。\n*   脚本执行完毕后，**复制输出末尾显示的 Image URIs**，下一步部署需要用到。\n\n### 第三步：部署 CloudFormation 栈\n\n根据需求选择部署架构（推荐大多数场景使用 **API Gateway + Lambda** 以降低成本）。\n\n1.  下载对应的模板文件：\n    *   API Gateway + Lambda: [`deployment\u002FBedrockProxy.template`](https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway\u002Fblob\u002Fmain\u002Fdeployment\u002FBedrockProxy.template)\n    *   ALB + Fargate: [`deployment\u002FBedrockProxyFargate.template`](https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway\u002Fblob\u002Fmain\u002Fdeployment\u002FBedrockProxyFargate.template)\n2.  登录 AWS 控制台，进入 **CloudFormation** 服务，点击 **\"Create stack\"** -> **\"With new resources\"**。\n3.  上传下载的模板文件。\n4.  在 **\"Specify stack details\"** 页面填写参数：\n    *   **Stack name**: 自定义名称（如 `BedrockProxyAPI`）。\n    *   **ApiKeySecretArn**: 填入第一步记录的 Secret ARN。\n    *   **ContainerImageUri**: 填入第二步获取的 ECR 镜像 URI。\n    *   **DefaultModelId**: (可选) 指定默认模型。\n5.  勾选底部的 **\"I acknowledge that AWS CloudFormation might create IAM resources\"**，点击 **Submit**。\n\n部署完成后，在栈的 **Outputs** 标签页找到 `APIBaseUrl`，即为你的代理接口地址（格式类似 `http:\u002F\u002Fxxxx.xxx.elb.amazonaws.com\u002Fapi\u002Fv1`）。\n\n## 基本使用\n\n部署成功后，只需配置环境变量即可像使用 OpenAI 一样调用 Bedrock 模型。\n\n### 1. 配置环境变量\n\n```bash\nexport OPENAI_API_KEY=\u003C你在第一步设置的自定义 API Key>\nexport OPENAI_BASE_URL=\u003C从 CloudFormation Outputs 获取的 APIBaseUrl>\n# 兼容旧版 SDK\nexport OPENAI_API_BASE=\u003C从 CloudFormation Outputs 获取的 APIBaseUrl>\n```\n\n### 2. 使用 cURL 测试\n\n以下示例调用 Claude 3 Sonnet 模型：\n\n```bash\ncurl $OPENAI_BASE_URL\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n    \"model\": \"anthropic.claude-3-sonnet-20240229-v1:0\",\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Hello!\"\n      }\n    ]\n  }'\n```\n\n### 3. 使用 Python SDK\n\n确保已安装 openai 库 (`pip install openai`)：\n\n```python\nfrom openai import OpenAI\n\n# 初始化客户端，自动读取环境变量\nclient = OpenAI()\n\ncompletion = client.chat.completions.create(\n    model=\"anthropic.claude-3-sonnet-20240229-v1:0\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n)\n\nprint(completion.choices[0].message.content)\n```\n\n> **提示**：支持的功能包括流式响应 (SSE)、Tool Call、多模态输入、推理模式 (Reasoning) 以及 Prompt Caching。详细用法可参考项目官方文档。","某初创团队正在开发一款基于 AutoGen 框架的多智能体代码辅助平台，希望快速接入 Amazon Bedrock 上最新的 Claude 4.5 和 Qwen3-Coder 模型以提升推理能力。\n\n### 没有 bedrock-access-gateway 时\n- **代码重构成本高**：现有系统完全基于 OpenAI SDK 构建，若要切换至 Bedrock，需重写所有 API 调用逻辑并修改底层通信协议。\n- **流式响应延迟大**：直接集成 Bedrock 原生接口难以在 Serverless 架构下实现低延迟的 SSE（服务器发送事件）流式输出，导致用户等待首字时间过长。\n- **新模型适配慢**：面对 Bedrock 上新发布的 DeepSeek-R1 或 Nova 系列模型，每次都需要单独开发适配器，无法通过统一接口即时调用。\n- **高级功能缺失**：难以在不改动业务代码的前提下，利用 Bedrock 特有的思维链（Reasoning）或多模态处理能力。\n\n### 使用 bedrock-access-gateway 后\n- **零代码迁移**：bedrock-access-gateway 提供了兼容 OpenAI 的 RESTful API，团队无需修改任何一行业务代码，仅需更换 Endpoint 即可无缝调用 Bedrock 模型。\n- **极致流式体验**：借助 API Gateway 的原生流式支持，bedrock-access-gateway 实现了真正的低延迟字符级流式输出，显著提升了多智能体对话的流畅度。\n- **即时模型迭代**：只需运行一次模型刷新指令，AutoGen 框架即可立即识别并调用最新的 Claude 4.5 或 Qwen3-Coder 模型，大幅缩短测试周期。\n- **高级特性开箱即用**：通过标准 OpenAI 参数格式，直接开启了模型的深度推理（Extended Thinking）和工具调用（Tool Call）功能，释放了 Bedrock 的全部潜力。\n\nbedrock-access-gateway 充当了通用的“翻译官”，让开发者能以最小的成本将成熟的 OpenAI 生态应用平滑迁移至更具性价比和模型多样性的 Amazon Bedrock 平台。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Faws-samples_bedrock-access-gateway_27ca6ef4.png","aws-samples","AWS Samples","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Faws-samples_84ebd8ed.png","",null,"https:\u002F\u002Famazon.com\u002Faws","https:\u002F\u002Fgithub.com\u002Faws-samples",[83,87,91],{"name":84,"color":85,"percentage":86},"Python","#3572A5",93.1,{"name":88,"color":89,"percentage":90},"Shell","#89e051",5.9,{"name":92,"color":93,"percentage":94},"Dockerfile","#384d54",0.9,957,286,"2026-04-01T11:54:27","MIT-0","未说明 (基于 AWS Lambda\u002FFargate 容器化部署，宿主系统无特定限制)","不需要 (基于 AWS Bedrock 云端推理，本地\u002F容器端无需 GPU)","未说明 (取决于所选部署架构：Lambda 默认内存或 Fargate 任务定义配置)",{"notes":103,"python":104,"dependencies":105},"该工具并非本地运行的 AI 模型，而是部署在 AWS 云上的代理网关。核心需求包括：1. 必须拥有 Amazon Bedrock 模型访问权限；2. 需在 AWS Secrets Manager 中配置 API Key；3. 支持两种部署架构：API Gateway + Lambda（无服务器，按请求付费）或 ALB + Fargate（低延迟，需 VPC）；4. 需将提供的 Docker 镜像构建并推送至 Amazon ECR；5. 通过 CloudFormation 模板完成最终部署；6. 客户端仅需标准 OpenAI SDK 即可调用。","未说明 (封装在 Docker 镜像中，脚本示例使用 bash)",[106,107,108,109,110,111],"Docker","AWS CLI","Amazon Bedrock Access","AWS Secrets Manager","Amazon ECR","CloudFormation",[16],[114,115,116,117,118,119],"bedrock","genai","openai","openai-api","openai-proxy","proxy","2026-03-27T02:49:30.150509","2026-04-06T08:40:51.611042",[123,128,133,138,143,147],{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},11939,"为什么开启流式传输（stream=true）时无法获取 Token 用量（usage 为 null）？","这是因为部署架构不同导致的。README 中提供了两种部署方式：\n1. **ALB + Lambda**：这种模式下，流式响应会等待所有数据返回后才一次性返回，因此无法实时获取 usage。\n2. **ALB + Fargate**：这种模式支持正常的流式传输。\n\n如果您需要在流式模式下获取 Token 用量，请确保您使用的是 **ALB + Fargate** 的部署方式。","https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway\u002Fissues\u002F28",{"id":129,"question_zh":130,"answer_zh":131,"source_url":132},11940,"调用 API 时遇到 \"502 Bad Gateway\" 错误该如何排查？","如果遇到 502 错误，请按以下步骤排查：\n1. **检查 ECS 任务状态**：确认 ECS 任务是否正在运行。\n2. **启用 ALB 访问日志**：\n   - 进入 EC2 控制台，找到对应的 Load Balancer。\n   - 点击 \"Actions\" 菜单，选择 \"Edit load balancer attributes\"。\n   - 启用 \"access logs\" 以查看详细错误信息。\n3. **检查部署时间**：确认是否在部署完成后立即访问（通常部署只需 5 分钟）。\n4. **检查 API Key 配置**：确认是否正确配置了 Secrets Manager 中的 API Key ARN 或参数。","https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway\u002Fissues\u002F111",{"id":134,"question_zh":135,"answer_zh":136,"source_url":137},11941,"在 AWS Fargate 上部署时，并发请求为何变成串行处理？","该问题是由于早期版本中 boto3 同步调用阻塞导致的。目前项目已更新为异步调用 converse API，性能已得到改善。\n\n**解决方案**：\n- 重新部署服务或更新容器镜像到最新版本即可解决。\n- 如果您急需修复且无法等待官方合并，可以基于 PR #23 自行构建镜像，或使用社区维护的分支版本（如 `Wh1isper\u002Fbedway`）。","https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway\u002Fissues\u002F22",{"id":139,"question_zh":140,"answer_zh":141,"source_url":142},11942,"更新代码后启动失败，提示 API Key 相关错误（RuntimeError），如何解决？","最近的代码更新（PR #182）移除了默认的 API Key 回退机制（以前未设置时默认为 \"bedrock\"），现在必须显式设置 API Key 才能启动。\n\n**解决方法**：\n请在您的 `.env` 文件或环境变量中明确设置以下任一变量：\n- `API_KEY=your-api-key-here`\n- 或者配置 `API_KEY_PARAM_NAME`\n- 或者配置 `API_KEY_SECRET_ARN`\n\n例如：`API_KEY=bedrock` 或其他您自定义的密钥。","https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbedrock-access-gateway\u002Fissues\u002F188",{"id":144,"question_zh":145,"answer_zh":146,"source_url":142},11943,"如何正确配置 API Key 以通过验证？","根据最新配置要求，您不能依赖默认值，必须在环境变量中指定 API Key。您可以通过以下三种方式之一进行配置：\n1. **直接设置密钥**：`export API_KEY=your-secret-key`\n2. **使用 Systems Manager 参数**：设置 `API_KEY_PARAM_NAME` 指向参数名称。\n3. **使用 Secrets Manager**：设置 `API_KEY_SECRET_ARN` 指向密钥的 ARN。\n\n确保在 Docker Compose 或 ECS 任务定义中包含这些环境变量。",{"id":148,"question_zh":149,"answer_zh":150,"source_url":132},11944,"部署后 ECS 显示没有集群或任务未运行，可能是什么原因？","这通常与 CloudFormation 堆栈部署不完整或配置错误有关。建议检查以下几点：\n1. **CloudFormation 事件日志**：查看是否有资源创建失败的记录。\n2. **ECS 服务状态**：确认服务是否尝试启动任务但失败（可能是 IAM 权限不足或镜像拉取失败）。\n3. **API Key 配置**：如果使用了新的 ARN 风格配置，请确认 Secrets Manager 中的密钥存在且 ARN 正确。\n4. **网络配置**：确认子网和安全组允许 ECS 任务访问互联网（如果需要拉取镜像）或访问 Bedrock 端点。",[]]