{"id":317,"date":"2026-10-13T02:16:11","date_gmt":"2026-10-13T02:16:11","guid":{"rendered":"https:\/\/ntokenx.com\/blog\/index.php\/2026\/10\/13\/spring-ai-api\/"},"modified":"2026-10-13T02:16:11","modified_gmt":"2026-10-13T02:16:11","slug":"spring-ai-api","status":"publish","type":"post","link":"https:\/\/ntokenx.com\/blog\/index.php\/2026\/10\/13\/spring-ai-api\/","title":{"rendered":"Spring AI\u63a5\u5165\u7b2c\u4e09\u65b9\u5927\u6a21\u578bAPI\u670d\u52a1\uff1aBaseURL\u4e0e\u5bc6\u94a5\u914d\u7f6e\u5b9e\u64cd"},"content":{"rendered":"<p><em>\u4f5c\u8005\uff1anTokenX\uff5c\u53d1\u5e03\u65e5\u671f\uff1a2026-10-13\uff5c\u66f4\u65b0\u65e5\u671f\uff1a2026-10-13<\/em><\/p>\n<p>Spring AI\u63a5\u5165\u7b2c\u4e09\u65b9\u5927\u6a21\u578bAPI\u670d\u52a1\uff0c\u672c\u8d28\u662f\u8ba9 OpenAI \u6a21\u578b\u9002\u914d\u5668\u628a\u8bf7\u6c42\u53d1\u9001\u5230\u517c\u5bb9\u7f51\u5173\u3002\u5f00\u53d1\u8005\u901a\u5e38\u53ea\u9700\u5904\u7406\u4f9d\u8d56\u3001BaseURL\u3001API Key \u548c\u6a21\u578b\u540d\u56db\u9879\u914d\u7f6e\uff0c\u4f46\u8981\u7279\u522b\u68c0\u67e5 URL \u8def\u5f84\u3001\u5c5e\u6027\u7248\u672c\u548c\u6a21\u578b\u6807\u8bc6\u662f\u5426\u5339\u914d\u3002<\/p>\n<h2>Spring AI\u5982\u4f55\u8fde\u63a5\u7b2c\u4e09\u65b9\u5927\u6a21\u578bAPI\uff1f<\/h2>\n<p><strong>Spring AI\u901a\u8fc7\u7edf\u4e00\u7684 ChatModel \u4e0e ChatClient \u62bd\u8c61\u8c03\u7528\u6a21\u578b<\/strong>\u3002\u5982\u679c\u7b2c\u4e09\u65b9\u670d\u52a1\u63d0\u4f9b OpenAI \u517c\u5bb9\u534f\u8bae\uff0c\u5e94\u7528\u4e00\u822c\u65e0\u9700\u4e3a GPT\u3001Claude\u3001Gemini \u6216 Grok \u5206\u522b\u7f16\u5199\u5ba2\u6237\u7aef\uff0c\u53ea\u9700\u66f4\u6362\u7f51\u5173\u5730\u5740\u3001\u5bc6\u94a5\u4e0e\u6a21\u578b\u540d\u3002<\/p>\n<p>\u7b2c\u4e09\u65b9\u670d\u52a1\u901a\u5e38\u5206\u4e3a\u4e24\u7c7b\uff1a<\/p>\n<ol>\n<li><strong>\u6b63\u89c4API\u805a\u5408\u6216\u7f51\u5173<\/strong>\uff1a\u4f01\u4e1a\u7ed1\u5b9a\u81ea\u5df1\u7684\u6a21\u578b\u5382\u5546 Key\uff0c\u7531\u5e73\u53f0\u7edf\u4e00\u5b8c\u6210\u8f6c\u53d1\u3001\u76d1\u63a7\u4e0e\u8ba1\u8d39\u3002<\/li>\n<li><strong>\u7b2c\u4e09\u65b9\u6a21\u578b\u4e2d\u8f6c\u670d\u52a1<\/strong>\uff1a\u670d\u52a1\u5546\u91c7\u8d2d\u6216\u4ee3\u7406\u6a21\u578b\u989d\u5ea6\uff0c\u518d\u901a\u8fc7\u7edf\u4e00\u63a5\u53e3\u63d0\u4f9b\u8c03\u7528\u80fd\u529b\u3002<\/li>\n<\/ol>\n<p>\u7b2c\u4e8c\u7c7b\u670d\u52a1\u5728\u6388\u6743\u65b9\u5f0f\u3001\u53ef\u7528\u6027\u548c\u6570\u636e\u5b89\u5168\u65b9\u9762\u5dee\u5f02\u8f83\u5927\u3002\u4f01\u4e1a\u9009\u578b\u65f6\u5e94\u68c0\u67e5\u6570\u636e\u7559\u5b58\u3001\u5bc6\u94a5\u7ba1\u7406\u3001\u6545\u969c\u5904\u7406\u4e0e\u8d26\u5355\u6838\u5bf9\u673a\u5236\uff0c\u53ef\u53c2\u8003<a href=\"https:\/\/ntokenx.com\/blog\/index.php\/2026\/09\/23\/domestic-ai-api-aggregation\/\">\u591a\u6a21\u578bAPI\u805a\u5408\u5e73\u53f0\u7684\u5408\u89c4\u4e0e\u9009\u578b\u65b9\u6cd5<\/a>\u3002<\/p>\n<figure class=\"wp-block-image size-large\" style=\"margin:1.5em 0;\"><img decoding=\"async\" src=\"https:\/\/ntokenx.com\/blog\/wp-content\/uploads\/2026\/10\/backend-6323-1.jpg\" alt=\"Spring AI\u63a5\u5165\u7b2c\u4e09\u65b9\u5927\u6a21\u578bAPI\u670d\u52a1\u7684\u8bf7\u6c42\u94fe\u8def\u56fe\" style=\"max-width:100%;height:auto;\"><\/figure>\n<h2>\u63a5\u5165\u524d\u9700\u8981\u51c6\u5907\u54ea\u4e9b\u53c2\u6570\uff1f<\/h2>\n<p><strong>\u6700\u5c0f\u63a5\u5165\u53c2\u6570\u53ea\u6709\u4e09\u4e2a\uff1a\u517c\u5bb9\u63a5\u53e3\u7684BaseURL\u3001API Key\u548c\u51c6\u786e\u7684\u6a21\u578bID<\/strong>\u3002\u5176\u4e2d\u6a21\u578b\u5c55\u793a\u540d\u79f0\u4e0d\u4e00\u5b9a\u7b49\u4e8e\u8bf7\u6c42\u53c2\u6570\uff0c\u5fc5\u987b\u4f7f\u7528\u670d\u52a1\u5546\u63a5\u53e3\u6587\u6863\u6216\u6a21\u578b\u5217\u8868\u8fd4\u56de\u7684\u6807\u8bc6\u3002<\/p>\n<div style=\"overflow-x:auto;\">\n<table style=\"width:100%;border-collapse:collapse;margin:1.5em 0;font-size:0.95em;\">\n<thead>\n<tr>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u53c2\u6570<\/th>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u793a\u4f8b\u5360\u4f4d\u503c<\/th>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u6838\u5bf9\u91cd\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">BaseURL<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>${LLM_BASE_URL}<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u662f\u5426\u4e3a OpenAI \u517c\u5bb9\u5165\u53e3\uff0c\u8def\u5f84\u662f\u5426\u5305\u542b\u7248\u672c\u6bb5<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">API Key<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>${LLM_API_KEY}<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u662f\u5426\u6709\u76ee\u6807\u6a21\u578b\u6743\u9650\uff0c\u662f\u5426\u901a\u8fc7 Bearer \u9274\u6743<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u6a21\u578b\u540d<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>${LLM_MODEL}<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u5927\u5c0f\u5199\u3001\u7248\u672c\u540e\u7f00\u548c\u6e20\u9053\u524d\u7f00\u662f\u5426\u51c6\u786e<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u8d85\u65f6<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>60s<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u662f\u5426\u8986\u76d6\u6a21\u578b\u9996\u5b57\u5ef6\u8fdf<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u91cd\u8bd5\u6b21\u6570<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>3<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u4ec5\u5bf9\u53ef\u6062\u590d\u9519\u8bef\u91cd\u8bd5\uff0c\u907f\u514d\u653e\u5927\u8bf7\u6c42<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>nTokenX\u91c7\u7528\u7edf\u4e00\u5927\u6a21\u578bAPI\u65b9\u5f0f\uff0c\u7528\u6237\u7533\u8bf7\u4e00\u4e2a API Key\uff0c\u5373\u53ef\u8c03\u7528 GPT\u3001Claude\u3001Gemini\u3001Grok \u7b49\u591a\u4e2a\u6a21\u578b\u3002\u5207\u6362\u6a21\u578b\u65f6\uff0c\u4e1a\u52a1\u4ee3\u7801\u53ef\u4ee5\u4fdd\u6301\u4e0d\u53d8\uff0c\u4e3b\u8981\u8c03\u6574\u6a21\u578b\u6807\u8bc6\u3002<\/p>\n<h2>\u5982\u4f55\u6dfb\u52a0Spring AI\u4f9d\u8d56\uff1f<\/h2>\n<p><strong>\u4f7f\u7528Spring Boot\u81ea\u52a8\u914d\u7f6e\u65f6\uff0c\u53ea\u9700\u5f15\u5165OpenAI\u6a21\u578bStarter\uff0c\u5e76\u901a\u8fc7Spring AI BOM\u7edf\u4e00\u7ba1\u7406\u7248\u672c<\/strong>\u3002\u4e0d\u8981\u76f4\u63a5\u590d\u5236\u65e9\u671f\u6559\u7a0b\u4e2d\u7684\u65e7\u4f9d\u8d56\u540d\u79f0\uff0c\u5426\u5219\u53ef\u80fd\u5728\u4f9d\u8d56\u89e3\u6790\u9636\u6bb5\u5931\u8d25\u3002<\/p>\n<pre><code class=\"language-xml\">&lt;dependencyManagement&gt;\n    &lt;dependencies&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;org.springframework.ai&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-ai-bom&lt;\/artifactId&gt;\n            &lt;version&gt;${spring-ai.version}&lt;\/version&gt;\n            &lt;type&gt;pom&lt;\/type&gt;\n            &lt;scope&gt;import&lt;\/scope&gt;\n        &lt;\/dependency&gt;\n    &lt;\/dependencies&gt;\n&lt;\/dependencyManagement&gt;\n\n&lt;dependencies&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.ai&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-ai-starter-model-openai&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;\n<\/code><\/pre>\n<p><a href=\"https:\/\/docs.spring.io\/spring-ai\/reference\/api\/chat\/openai-chat.html\">Spring AI\u5b98\u65b9OpenAI Chat\u6587\u6863<\/a>\u5217\u51fa\u7684\u6a21\u578b Starter \u4e3a <code>spring-ai-starter-model-openai<\/code>\uff1b\u81ea\u52a8\u914d\u7f6e\u8fd8\u4f1a\u63d0\u4f9b\u53ef\u6ce8\u5165\u7684 <code>ChatClient.Builder<\/code>\u3002(<a href=\"https:\/\/docs.spring.io\/spring-ai\/reference\/api\/chat\/openai-chat.html\">docs.spring.io<\/a>)<\/p>\n<h2>BaseURL\u4e0eAPI Key\u5982\u4f55\u914d\u7f6e\uff1f<\/h2>\n<p><strong>\u63a8\u8350\u628a\u5bc6\u94a5\u653e\u5165\u73af\u5883\u53d8\u91cf\uff0c\u5e76\u5728YAML\u4e2d\u53ea\u4fdd\u7559\u53d8\u91cf\u5f15\u7528<\/strong>\u3002\u901a\u7528\u914d\u7f6e\u9002\u5408\u804a\u5929\u3001\u5d4c\u5165\u7b49\u80fd\u529b\u5171\u7528\u540c\u4e00\u7f51\u5173\uff1b\u5982\u679c\u53ea\u6709\u804a\u5929\u6a21\u578b\u8d70\u7b2c\u4e09\u65b9\u63a5\u53e3\uff0c\u53ef\u4f7f\u7528\u804a\u5929\u7ea7\u914d\u7f6e\u8986\u76d6\u901a\u7528\u5730\u5740\u3002<\/p>\n<pre><code class=\"language-yaml\">spring:\n  ai:\n    model:\n      chat: openai\n    openai:\n      base-url: ${LLM_BASE_URL}\n      api-key: ${LLM_API_KEY}\n      timeout: 60s\n      max-retries: 3\n      chat:\n        model: ${LLM_MODEL}\n        temperature: 0.2\n<\/code><\/pre>\n<pre><code class=\"language-bash\">export LLM_BASE_URL=&quot;https:\/\/gateway.example.com&quot;\nexport LLM_API_KEY=&quot;\u66ff\u6362\u4e3a\u771f\u5b9e\u5bc6\u94a5&quot;\nexport LLM_MODEL=&quot;\u66ff\u6362\u4e3a\u7f51\u5173\u6a21\u578bID&quot;\n<\/code><\/pre>\n<p>\u5b98\u65b9\u914d\u7f6e\u4e2d\uff0c<code>spring.ai.openai.chat.base-url<\/code> \u548c <code>spring.ai.openai.chat.api-key<\/code> \u7684\u4f18\u5148\u7ea7\u9ad8\u4e8e\u5bf9\u5e94\u7684\u901a\u7528\u5c5e\u6027\uff0c\u9002\u5408\u5c06\u804a\u5929\u4e0e\u5d4c\u5165\u6a21\u578b\u8def\u7531\u5230\u4e0d\u540c\u670d\u52a1\u3002(<a href=\"https:\/\/docs.spring.io\/spring-ai\/reference\/api\/chat\/openai-chat.html\">docs.spring.io<\/a>)<\/p>\n<p>\u4e0d\u8981\u628a Key \u5199\u5165 Git \u4ed3\u5e93\u3001\u955c\u50cf\u6587\u4ef6\u6216\u524d\u7aef\u4ee3\u7801\u3002\u751f\u4ea7\u73af\u5883\u5e94\u4f7f\u7528\u914d\u7f6e\u4e2d\u5fc3\u3001Kubernetes Secret \u6216\u4e91\u5bc6\u94a5\u7ba1\u7406\u670d\u52a1\uff0c\u5e76\u6309\u5e94\u7528\u3001\u73af\u5883\u548c\u79df\u6237\u62c6\u5206\u51ed\u8bc1\u3002<\/p>\n<h2>BaseURL\u662f\u5426\u5fc5\u987b\u5305\u542b\u201c\/v1\u201d\uff1f<\/h2>\n<p><strong>BaseURL\u6ca1\u6709\u9002\u7528\u4e8e\u6240\u6709\u7f51\u5173\u7684\u56fa\u5b9a\u5199\u6cd5<\/strong>\u3002\u6b63\u786e\u7ed3\u679c\u53d6\u51b3\u4e8e\u5ba2\u6237\u7aef\u6700\u7ec8\u8bf7\u6c42\u8def\u5f84\u4e0e\u7f51\u5173\u8def\u7531\u7684\u7ec4\u5408\uff0c\u56e0\u6b64\u4e0d\u80fd\u673a\u68b0\u5957\u7528\u201c\u5fc5\u987b\u5e26 <code>\/v1<\/code>\u201d\u6216\u201c\u5fc5\u987b\u5220\u9664 <code>\/v1<\/code>\u201d\u7684\u7ed3\u8bba\u3002<\/p>\n<p>\u672c\u6587\u91c7\u7528\u201c<strong>\u8def\u5f84\u62fc\u63a5\u4e09\u4f8b\u6cd5<\/strong>\u201d\u505a\u9759\u6001\u5ba1\u8ba1\u3002\u5bf9\u4e09\u7ec4\u5e38\u89c1\u7ec4\u5408\u6f14\u7b97\u540e\uff0c2 \u7ec4\u5f62\u6210\u76ee\u6807\u8def\u5f84\uff0c1 \u7ec4\u51fa\u73b0\u91cd\u590d\u7248\u672c\u6bb5\uff1a<\/p>\n<div style=\"overflow-x:auto;\">\n<table style=\"width:100%;border-collapse:collapse;margin:1.5em 0;font-size:0.95em;\">\n<thead>\n<tr>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">BaseURL<\/th>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u5ba2\u6237\u7aef\u8ffd\u52a0\u8def\u5f84<\/th>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u62fc\u63a5\u7ed3\u679c<\/th>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u7ed3\u8bba<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>https:\/\/api.example.com<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>\/v1\/chat\/completions<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>\/v1\/chat\/completions<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u6b63\u5e38<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>https:\/\/api.example.com\/v1<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>\/v1\/chat\/completions<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>\/v1\/v1\/chat\/completions<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u8def\u5f84\u91cd\u590d<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>https:\/\/api.example.com\/openai<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>\/v1\/chat\/completions<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>\/openai\/v1\/chat\/completions<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u9002\u5408\u5e26\u524d\u7f00\u7684\u7f51\u5173<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u8fd9\u9879\u6f14\u7b97\u7684\u4ef7\u503c\u5728\u4e8e\uff1a<strong>BaseURL\u5e94\u6839\u636e\u6700\u7ec8\u8bf7\u6c42\u5730\u5740\u53cd\u63a8\uff0c\u800c\u4e0d\u662f\u53ea\u770b\u914d\u7f6e\u5b57\u6bb5\u540d\u79f0<\/strong>\u3002\u82e5\u63a5\u53e3\u8fd4\u56de 404\uff0c\u5e94\u5148\u67e5\u770b\u5e94\u7528\u65e5\u5fd7\u6216\u7f51\u5173\u8bbf\u95ee\u65e5\u5fd7\uff0c\u786e\u8ba4\u5b9e\u9645\u8bf7\u6c42\u8def\u5f84\uff0c\u518d\u8c03\u6574\u7248\u672c\u6bb5\u548c\u524d\u7f00\u3002<\/p>\n<figure class=\"wp-block-image size-large\" style=\"margin:1.5em 0;\"><img decoding=\"async\" src=\"https:\/\/ntokenx.com\/blog\/wp-content\/uploads\/2026\/10\/backend-6323-2.jpg\" alt=\"Spring AI BaseURL\u4e0e\u63a5\u53e3\u8def\u5f84\u62fc\u63a5\u68c0\u67e5\u793a\u610f\u56fe\" style=\"max-width:100%;height:auto;\"><\/figure>\n<h2>\u5982\u4f55\u7f16\u5199\u6700\u5c0f\u53ef\u7528\u7684\u8c03\u7528\u63a5\u53e3\uff1f<\/h2>\n<p><strong>\u4f9d\u8d56\u4e0eYAML\u751f\u6548\u540e\uff0c\u53ef\u76f4\u63a5\u6ce8\u5165\u81ea\u52a8\u914d\u7f6e\u7684ChatClient.Builder<\/strong>\u3002\u5148\u7528\u975e\u6d41\u5f0f\u3001\u77ed\u63d0\u793a\u8bcd\u9a8c\u8bc1\u9274\u6743\u548c\u8def\u7531\uff0c\u518d\u63a5\u5165\u6d41\u5f0f\u8f93\u51fa\u3001\u5de5\u5177\u8c03\u7528\u6216\u4e1a\u52a1\u4e0a\u4e0b\u6587\u3002<\/p>\n<pre><code class=\"language-java\">package com.example.demo;\n\nimport org.springframework.ai.chat.client.ChatClient;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class AiController {\n\n    private final ChatClient chatClient;\n\n    public AiController(ChatClient.Builder builder) {\n        this.chatClient = builder.build();\n    }\n\n    @GetMapping(&quot;\/ai\/chat&quot;)\n    public String chat(\n            @RequestParam(defaultValue = &quot;\u7528\u4e00\u53e5\u8bdd\u4ecb\u7ecdSpring AI&quot;) String question) {\n\n        return chatClient.prompt()\n                .user(question)\n                .call()\n                .content();\n    }\n}\n<\/code><\/pre>\n<p>\u542f\u52a8\u5e94\u7528\u540e\u8bf7\u6c42\uff1a<\/p>\n<pre><code class=\"language-bash\">curl &quot;http:\/\/localhost:8080\/ai\/chat?question=\u8fd4\u56de\u5b57\u7b26\u4e32OK&quot;\n<\/code><\/pre>\n<p>\u5efa\u8bae\u628a\u9a8c\u6536\u7ed3\u679c\u91cf\u5316\u4e3a <strong>4\/4\u901a\u8fc7<\/strong>\uff1a<\/p>\n<ol>\n<li>Maven\u4f9d\u8d56\u6210\u529f\u89e3\u6790\uff1b<\/li>\n<li>\u5e94\u7528\u542f\u52a8\u4e14 <code>ChatClient.Builder<\/code> \u6ce8\u5165\u6210\u529f\uff1b<\/li>\n<li>\u975e\u6d41\u5f0f\u8bf7\u6c42\u8fd4\u56de\u975e\u7a7a\u6587\u672c\uff1b<\/li>\n<li>\u7f51\u5173\u8d26\u5355\u6216\u8c03\u7528\u65e5\u5fd7\u51fa\u73b0\u5bf9\u5e94\u6a21\u578b\u8bb0\u5f55\u3002<\/li>\n<\/ol>\n<p>\u53ea\u6709\u542f\u52a8\u6210\u529f\u4e0d\u80fd\u8bc1\u660e\u63a5\u5165\u5b8c\u6210\uff0c\u56e0\u4e3a\u5b83\u4ec5\u8bf4\u660e\u914d\u7f6e\u88ab\u52a0\u8f7d\uff0c\u4e0d\u4ee3\u8868\u5bc6\u94a5\u3001\u8def\u7531\u548c\u6a21\u578b\u6743\u9650\u90fd\u6b63\u786e\u3002<\/p>\n<h2>\u5e38\u89c1\u9519\u8bef\u5982\u4f55\u5feb\u901f\u5b9a\u4f4d\uff1f<\/h2>\n<p><strong>\u6392\u9519\u5e94\u6309\u7167\u201c\u4f9d\u8d56\u2014\u914d\u7f6e\u2014\u8def\u7531\u2014\u6a21\u578b\u2014\u9650\u6d41\u201d\u7684\u987a\u5e8f\u8fdb\u884c<\/strong>\u3002\u5148\u786e\u8ba4\u8bf7\u6c42\u662f\u5426\u771f\u6b63\u5230\u8fbe\u7f51\u5173\uff0c\u518d\u5224\u65ad\u662f\u5ba2\u6237\u7aef\u53c2\u6570\u9519\u8bef\u8fd8\u662f\u670d\u52a1\u7aef\u5bb9\u91cf\u95ee\u9898\u3002<\/p>\n<div style=\"overflow-x:auto;\">\n<table style=\"width:100%;border-collapse:collapse;margin:1.5em 0;font-size:0.95em;\">\n<thead>\n<tr>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u73b0\u8c61<\/th>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u5e38\u89c1\u539f\u56e0<\/th>\n<th style=\"border:1px solid #e3e6ea;padding:8px 12px;background:#f6f8fa;text-align:left;font-weight:600;\">\u5904\u7406\u65b9\u6cd5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u542f\u52a8\u65f6\u62a5\u627e\u4e0d\u5230\u7c7b<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">Starter\u540d\u79f0\u6216\u7248\u672c\u4e0d\u5339\u914d<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u4f7f\u7528BOM\u5e76\u68c0\u67e5\u5b9e\u9645\u4f9d\u8d56\u6811<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">401\u6216403<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">Key\u9519\u8bef\u3001\u5931\u6548\u6216\u6ca1\u6709\u6a21\u578b\u6743\u9650<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u66f4\u6362\u6709\u9650\u6743\u9650\u6d4b\u8bd5Key\uff0c\u6838\u5bf9\u9274\u6743\u5934<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">404<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">BaseURL\u8def\u5f84\u9519\u8bef\u6216\u91cd\u590d <code>\/v1<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u67e5\u770b\u6700\u7ec8\u8bf7\u6c42URL\uff0c\u4e0d\u8981\u76f2\u76ee\u6539\u57df\u540d<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\"><code>model_not_found<\/code><\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u6a21\u578bID\u586b\u5199\u9519\u8bef<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u4f7f\u7528\u63a5\u53e3\u8fd4\u56de\u7684\u6a21\u578b\u6807\u8bc6<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">400\u53c2\u6570\u9519\u8bef<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u7f51\u5173\u4e0d\u652f\u6301\u67d0\u4e2a\u8bf7\u6c42\u5b57\u6bb5<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u5148\u79fb\u9664\u6e29\u5ea6\u3001\u5de5\u5177\u8c03\u7528\u7b49\u53ef\u9009\u53c2\u6570<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">429<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u914d\u989d\u3001\u5e76\u53d1\u6216\u901f\u7387\u9650\u5236<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u4f7f\u7528\u6307\u6570\u9000\u907f\u3001\u6296\u52a8\u548c\u964d\u7ea7\u8def\u7531<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u666e\u901a\u8bf7\u6c42\u6210\u529f\u3001\u6d41\u5f0f\u5931\u8d25<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u7f51\u5173\u672a\u6b63\u786e\u8f6c\u53d1SSE<\/td>\n<td style=\"border:1px solid #e3e6ea;padding:8px 12px;vertical-align:top;\">\u68c0\u67e5\u54cd\u5e94\u5934\u3001\u7f13\u51b2\u4e0e\u53cd\u5411\u4ee3\u7406\u8bbe\u7f6e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u9488\u5bf9\u9650\u6d41\u573a\u666f\uff0c\u53ef\u7ed3\u5408<a href=\"https:\/\/ntokenx.com\/blog\/index.php\/2026\/10\/04\/llm-429-retry\/\">\u5927\u6a21\u578bAPI\u9519\u8bef\u7801429\u81ea\u52a8\u91cd\u8bd5\u7b56\u7565<\/a>\u8bbe\u8ba1\u9000\u907f\u4e0e\u6296\u52a8\uff1b\u751f\u4ea7\u7cfb\u7edf\u8fd8\u5e94\u901a\u8fc7<a href=\"https:\/\/ntokenx.com\/blog\/index.php\/2026\/10\/03\/llm-api-failover\/\">\u5927\u6a21\u578bAPI\u591a\u4e91\u5bb9\u707e\u4e0e\u81ea\u52a8\u964d\u7ea7\u65b9\u6848<\/a>\u907f\u514d\u5355\u4e00\u63a5\u53e3\u6545\u969c\u6269\u5927\u3002<\/p>\n<h2>\u751f\u4ea7\u73af\u5883\u8fd8\u8981\u68c0\u67e5\u4ec0\u4e48\uff1f<\/h2>\n<p><strong>\u751f\u4ea7\u63a5\u5165\u4e0d\u80fd\u505c\u7559\u5728\u201c\u80fd\u8fd4\u56de\u6587\u672c\u201d\uff0c\u8fd8\u8981\u9a8c\u8bc1\u5bc6\u94a5\u9694\u79bb\u3001\u8d85\u65f6\u3001\u91cd\u8bd5\u3001\u65e5\u5fd7\u8131\u654f\u548c\u6a21\u578b\u5207\u6362<\/strong>\u3002\u7edf\u4e00\u7f51\u5173\u964d\u4f4e\u4e86SDK\u9002\u914d\u6210\u672c\uff0c\u4f46\u4e0d\u4f1a\u81ea\u52a8\u89e3\u51b3\u6cbb\u7406\u95ee\u9898\u3002<\/p>\n<p>\u4e0a\u7ebf\u524d\u81f3\u5c11\u5b8c\u6210\u4ee5\u4e0b\u68c0\u67e5\uff1a<\/p>\n<ul>\n<li>\u4e3a\u5f00\u53d1\u3001\u6d4b\u8bd5\u3001\u751f\u4ea7\u73af\u5883\u4f7f\u7528\u4e0d\u540c Key\uff1b<\/li>\n<li>\u65e5\u5fd7\u4e0d\u8bb0\u5f55 Authorization \u8bf7\u6c42\u5934\u548c\u5b8c\u6574\u63d0\u793a\u8bcd\uff1b<\/li>\n<li>\u4e3a\u8bf7\u6c42\u8bbe\u7f6e\u8fde\u63a5\u8d85\u65f6\u3001\u8bfb\u53d6\u8d85\u65f6\u548c\u6700\u5927\u91cd\u8bd5\u6b21\u6570\uff1b<\/li>\n<li>\u8bb0\u5f55\u6a21\u578b\u540d\u3001\u8017\u65f6\u3001\u72b6\u6001\u7801\u548c\u8bf7\u6c42\u8ffd\u8e2aID\uff1b<\/li>\n<li>\u5bf9 429\u30015xx \u548c\u8d85\u65f6\u5206\u522b\u5236\u5b9a\u91cd\u8bd5\u89c4\u5219\uff1b<\/li>\n<li>\u4e3a\u6838\u5fc3\u4e1a\u52a1\u914d\u7f6e\u5907\u7528\u6a21\u578b\u6216\u5907\u7528\u7f51\u5173\uff1b<\/li>\n<li>\u7528\u56fa\u5b9a\u6d4b\u8bd5\u96c6\u6bd4\u8f83\u5207\u6362\u6a21\u578b\u524d\u540e\u7684\u683c\u5f0f\u4e0e\u8bed\u4e49\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u9700\u8981\u7528\u4e00\u4e2a\u5bc6\u94a5\u7edf\u4e00\u8c03\u7528\u591a\u4e2a\u6a21\u578b\uff0c\u53ef<a href=\"https:\/\/ntokenx.com\/\">\u6ce8\u518c nTokenX<\/a>\uff0c\u518d\u5c06\u83b7\u5f97\u7684 BaseURL\u3001API Key \u4e0e\u6a21\u578b\u6807\u8bc6\u586b\u5165\u4e0a\u8ff0\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<h2>\u5e38\u89c1\u95ee\u9898<\/h2>\n<h3>Spring AI\u53ea\u80fd\u8c03\u7528OpenAI\u6a21\u578b\u5417\uff1f<\/h3>\n<p>\u4e0d\u662f\u3002Spring AI\u63d0\u4f9b\u591a\u79cd\u6a21\u578b\u9002\u914d\u5668\uff1b\u5bf9\u4e8e\u63d0\u4f9b OpenAI \u517c\u5bb9\u534f\u8bae\u7684\u7b2c\u4e09\u65b9\u7f51\u5173\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7 OpenAI \u6a21\u578b Starter \u8f6c\u53d1\u5230\u5176\u4ed6\u6a21\u578b\uff0c\u4f46\u5177\u4f53\u80fd\u529b\u53d6\u51b3\u4e8e\u7f51\u5173\u7684\u534f\u8bae\u8f6c\u6362\u8303\u56f4\u3002<\/p>\n<h3>\u4e3a\u4ec0\u4e48\u914d\u7f6e\u6b63\u786e\u4ecd\u7136\u63d0\u793a\u6a21\u578b\u4e0d\u5b58\u5728\uff1f<\/h3>\n<p>\u6700\u5e38\u89c1\u539f\u56e0\u662f\u586b\u5199\u4e86\u63a7\u5236\u53f0\u5c55\u793a\u540d\uff0c\u800c\u4e0d\u662f\u63a5\u53e3\u5b9e\u9645\u63a5\u6536\u7684\u6a21\u578bID\u3002\u8fd8\u5e94\u68c0\u67e5\u8be5 Key \u662f\u5426\u62e5\u6709\u76ee\u6807\u6a21\u578b\u6743\u9650\uff0c\u4ee5\u53ca\u6a21\u578b\u540d\u662f\u5426\u5305\u542b\u6e20\u9053\u6216\u7248\u672c\u540e\u7f00\u3002<\/p>\n<h3>\u53ef\u4ee5\u628aAPI Key\u76f4\u63a5\u5199\u8fdbapplication.yml\u5417\uff1f<\/h3>\n<p>\u672c\u5730\u4e34\u65f6\u9a8c\u8bc1\u53ef\u4ee5\uff0c\u4f46\u4e0d\u5efa\u8bae\u63d0\u4ea4\u5230\u4ee3\u7801\u4ed3\u5e93\u3002\u6d4b\u8bd5\u548c\u751f\u4ea7\u73af\u5883\u5e94\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u3001\u914d\u7f6e\u4e2d\u5fc3\u6216\u5bc6\u94a5\u7ba1\u7406\u7cfb\u7edf\u6ce8\u5165\uff0c\u5e76\u5b9a\u671f\u8f6e\u6362\u3002<\/p>\n<h3>\u804a\u5929\u63a5\u53e3\u6210\u529f\u662f\u5426\u4ee3\u8868\u5d4c\u5165\u63a5\u53e3\u4e5f\u80fd\u4f7f\u7528\uff1f<\/h3>\n<p>\u4e0d\u4ee3\u8868\u3002\u804a\u5929\u4e0e\u5d4c\u5165\u53ef\u80fd\u4f7f\u7528\u4e0d\u540c\u6a21\u578b\u3001\u8def\u5f84\u751a\u81f3\u4e0d\u540c\u670d\u52a1\u5546\u3002\u9700\u8981\u5206\u522b\u6267\u884c\u6700\u5c0f\u8bf7\u6c42\uff0c\u5e76\u5728\u5fc5\u8981\u65f6\u4f7f\u7528\u804a\u5929\u7ea7\u6216\u5d4c\u5165\u7ea7 BaseURL \u8986\u76d6\u901a\u7528\u914d\u7f6e\u3002<\/p>\n<h3>\u66f4\u6362\u7b2c\u4e09\u65b9\u7f51\u5173\u9700\u8981\u4fee\u6539Java\u4ee3\u7801\u5417\uff1f<\/h3>\n<p>\u5982\u679c\u65b0\u7f51\u5173\u4fdd\u6301 OpenAI \u517c\u5bb9\u8bf7\u6c42\u7ed3\u6784\uff0c\u901a\u5e38\u53ea\u9700\u4fee\u6539 BaseURL\u3001API Key \u548c\u6a21\u578b\u540d\u3002\u82e5\u5176\u5de5\u5177\u8c03\u7528\u3001\u6d41\u5f0f\u54cd\u5e94\u6216\u591a\u6a21\u6001\u5b57\u6bb5\u4e0d\u517c\u5bb9\uff0c\u4ecd\u9700\u8c03\u6574\u8bf7\u6c42\u53c2\u6570\u6216\u6a21\u578b\u9002\u914d\u5c42\u3002<\/p>\n<p><script type=\"application\/ld+json\">\n{\"@context\":\"https:\/\/schema.org\",\"@type\":\"Article\",\"author\":{\"@type\":\"Organization\",\"name\":\"nTokenX\"},\"dateModified\":\"2026-10-13\",\"datePublished\":\"2026-10-13\",\"description\":\"Spring AI\u63a5\u5165\u7b2c\u4e09\u65b9\u5927\u6a21\u578bAPI\u670d\u52a1\uff0c\u5173\u952e\u662f\u6b63\u786e\u914d\u7f6eOpenAI\u517c\u5bb9\u7f51\u5173\u7684BaseURL\u3001API Key\u4e0e\u6a21\u578b\u540d\u3002\u672c\u6587\u63d0\u4f9b\u53ef\u590d\u5236\u7684Maven\u3001YAML\u548c\u63a7\u5236\u5668\u793a\u4f8b\uff0c\u5e76\u7528\u56db\u5c42\u9a8c\u6536\u6cd5\u6392\u67e5401\u3001404\u3001429\u53ca\u6d41\u5f0f\u54cd\u5e94\u95ee\u9898\uff0c\u7167\u6b65\u9aa4\u914d\u7f6e\u5e76\u7acb\u5373\u9a8c\u8bc1\u3002\",\"headline\":\"Spring AI\u63a5\u5165\u7b2c\u4e09\u65b9\u5927\u6a21\u578bAPI\u670d\u52a1\uff1aBaseURL\u4e0e\u5bc6\u94a5\u914d\u7f6e\u5b9e\u64cd\",\"image\":\"https:\/\/ntokenx.com\/blog\/wp-content\/uploads\/2026\/10\/art-10190-cover.jpg\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"nTokenX\"}}\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring AI\u63a5\u5165\u7b2c\u4e09\u65b9\u5927\u6a21\u578bAPI\u670d\u52a1\uff0c\u5173\u952e\u662f\u6b63\u786e\u914d\u7f6eOpenAI\u517c\u5bb9\u7f51\u5173\u7684BaseURL\u3001API Key\u4e0e\u6a21\u578b\u540d\u3002\u672c\u6587\u63d0\u4f9b\u53ef\u590d\u5236\u7684Maven\u3001YAML\u548c\u63a7\u5236\u5668\u793a\u4f8b\uff0c\u5e76\u7528\u56db\u5c42\u9a8c\u6536\u6cd5\u6392\u67e5401\u3001404\u3001429\u53ca\u6d41\u5f0f\u54cd\u5e94\u95ee\u9898\uff0c\u7167\u6b65\u9aa4\u914d\u7f6e\u5e76\u7acb\u5373\u9a8c\u8bc1\u3002<\/p>\n","protected":false},"author":1,"featured_media":316,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-317","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=317"}],"version-history":[{"count":0,"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/317\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/316"}],"wp:attachment":[{"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ntokenx.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}