{"id":22849,"date":"2024-05-26T10:35:39","date_gmt":"2024-05-26T03:35:39","guid":{"rendered":"https:\/\/huongdanjava.com\/?p=22849"},"modified":"2025-12-22T18:56:11","modified_gmt":"2025-12-22T11:56:11","slug":"an-introduction-about-spring-ai","status":"publish","type":"post","link":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html","title":{"rendered":"An introduction about Spring AI"},"content":{"rendered":"<p><a href=\"https:\/\/spring.io\/projects\/spring-ai\" target=\"_blank\" rel=\"noopener\">Spring AI<\/a> is a module of Spring that helps us easily work with applications that use AI, integrating with AI providers such as OpenAI, Azure OpenAI, Google Gemini, &#8230; In this tutorial, I will introduce you to all the basic knowledge about Spring AI so you can use it in applications that integrate with the AI providers!<\/p>\n<p>First, I will create a new Maven project as an example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-24979 size-full aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2024\/05\/an-introduction-about-spring-ai-1.png\" alt=\"\" width=\"700\" height=\"687\" \/><\/p>\n<p>I will make a small application that integrates with OpenAI to query information, so I have declared to use the OpenAI dependency as follows:<\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;dependency&gt;\r\n  &lt;groupId&gt;org.springframework.ai&lt;\/groupId&gt;\r\n  &lt;artifactId&gt;spring-ai-openai&lt;\/artifactId&gt;\r\n  &lt;version&gt;1.1.2&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<h3>Basic AI concepts<\/h3>\n<p>Before going into implementing the example, there are some concepts about AI that you need to understand, as follows:<\/p>\n<ul>\n<li><strong>Models<\/strong> are algorithms to process user request information and generate output appropriate to the request. These algorithms will use a large amount of input data to produce predictions, text, images, and other outputs.<\/li>\n<li><span style=\"font-size: 14px;\"><strong>Prompts<\/strong> can be roughly said as input requests from users, usually text input, for the AI model to rely on to generate output.<\/span><\/li>\n<li><span style=\"font-size: 14px;\"><strong>Prompt Templates<\/strong> are templates used to create prompts. We will need to replace the placeholders defined in the template with the values we want to create a prompt from these values.<\/span><\/li>\n<li><span style=\"font-size: 14px;\"><strong>Embeddings<\/strong> are objects that will transform user prompts into vector objects in the form of numbers that AI models can use to process requests.<\/span><\/li>\n<li><span style=\"font-size: 14px;\"><strong>Tokens<\/strong> are the basic linguistic units that the AI model uses to process prompts. At input, the AI model will convert words to tokens, and at output, the AI model will convert tokens to words.<\/span><\/li>\n<\/ul>\n<p>Understanding the basic concepts above, you will imagine at a high level how an AI application works!<\/p>\n<h3>Basic Spring AI<\/h3>\n<p>To integrate with AI providers, Spring AI defines an interface Model with ModelRequest and ModelResponse:<\/p>\n<pre class=\"lang:java decode:true \">public interface Model&lt;TReq extends ModelRequest&lt;?&gt;, TRes extends ModelResponse&lt;?&gt;&gt; {\r\n  TRes call(TReq request);\r\n}<\/pre>\n<p>There are 7 sub-interfaces from the ModelClient interface:<\/p>\n<ul>\n<li>ChatModel<\/li>\n<li>ImageModel<\/li>\n<li>DocumentEmbeddingModel<\/li>\n<li>TextToSpeechModel<\/li>\n<li>TranscriptionModel<\/li>\n<li>ModerationModel<\/li>\n<li>v\u00e0 EmbeddingModel<\/li>\n<\/ul>\n<p>Corresponding to each AI provider, there will be its own implementation!<\/p>\n<p>For OpenAI, the implementations for the 6 interfaces ChatModel, ImageModel, TextToSpeechModel, TranscriptionModel, ModerationModel and EmbeddingModel are OpenAiChatModel, OpenAiImageModel, OpenAiAudioSpeechModel, OpenAiAudioTranscriptionModel, OpenAiModerationModel, OpenAiEmbeddingModel respectively.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-24980 size-full aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2024\/05\/an-introduction-about-spring-ai-2.png\" alt=\"\" width=\"700\" height=\"223\" \/><\/p>\n<p>For my example, I will use the ChatModel class to work with OpenAI!<\/p>\n<h3>Implement the example<\/h3>\n<p><strong>To integrate with OpenAI, first, you need to create a new API key in the OpenAI platform<\/strong> by going to <a href=\"https:\/\/platform.openai.com\/api-keys\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/api-keys<\/a> and clicking on the &#8220;Create new secret key&#8221; button as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-24981 size-full aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2024\/05\/an-introduction-about-spring-ai-3.png\" alt=\"\" width=\"700\" height=\"762\" \/><\/p>\n<p>This API key is used to authenticate with the OpenAI API! Please save this API key somewhere so you can use it again later!<\/p>\n<p>You will also need to add Credit:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24982 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2024\/05\/an-introduction-about-spring-ai-4.png\" alt=\"\" width=\"700\" height=\"394\" \/><\/p>\n<p>to use the OpenAI API without any limitations!<\/p>\n<p><strong>To configure OpenAI information with Spring AI, you can use the OpenAiApi class.<\/strong><\/p>\n<p>The constructor used to initialize this OpenAiApi class object has the following content:<\/p>\n<pre class=\"wrap:true lang:java decode:true \">public OpenAiApi(String baseUrl, ApiKey apiKey, MultiValueMap&lt;String, String&gt; headers, String completionsPath, String embeddingsPath, RestClient.Builder restClientBuilder, WebClient.Builder webClientBuilder, ResponseErrorHandler responseErrorHandler)<\/pre>\n<p>With:<\/p>\n<ul>\n<li>The baseUrl of OpenAI is used to query information. The default baseUrl of the OpenAI API is &#8220;https:\/\/api.openai.com&#8221;!<\/li>\n<li><span style=\"font-size: 14px;\">The apiKey is the API key we just created above.<\/span><\/li>\n<li><span style=\"font-size: 14px;\">headers are the headers you need to pass in your request to the OpenAI API.<\/span><\/li>\n<li><span style=\"font-size: 14px;\">completionsPath and embeddingsPath define the context path of the OpenAI API for chat or text generation and text embedding, respectively. By default, the values \u200b\u200bof these two context paths are &#8220;\/v1\/chat\/completions&#8221; and &#8220;\/v1\/embeddings&#8221;!<\/span><\/li>\n<li><span style=\"font-size: 14px;\">The restClientBuilder, webClientBuilder, and responseErrorHandler allow us to define configurations related to requests to OpenAI and handle errors when receiving responses from OpenAI.<\/span><\/li>\n<\/ul>\n<p>You can also use the OpenAiApi.Builder class to instantiate an object of the OpenAiApi class, as I did, as follows:<\/p>\n<pre class=\"lang:java decode:true\">@Bean\r\nOpenAiApi openAiApi() {\r\n  return new OpenAiApi.Builder()\r\n      .apiKey(\"&lt;YOUR_API_KEY_HERE&gt;\")\r\n      .build();\r\n}<\/pre>\n<p>Here, we&#8217;ll use Spring AI&#8217;s default configurations for the OpenAI API; only the API key needs to be configured separately!<\/p>\n<p>Now, <strong>we&#8217;ll initialize the ChatModel bean from the OpenAIApi object<\/strong> as follows:<\/p>\n<pre class=\"lang:java decode:true \">@Bean\r\nChatModel chatModel(OpenAiApi openAiApi, ToolCallingManager toolCallingManager,\r\n    RetryTemplate retryTemplate, ObservationRegistry observationRegistry) {\r\n  OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder()\r\n      .model(OpenAiApi.ChatModel.GPT_5_NANO)\r\n      .build();\r\n\r\n  return new OpenAiChatModel(openAiApi, openAiChatOptions, toolCallingManager, retryTemplate, \r\n      observationRegistry);\r\n}<\/pre>\n<p>with the beans of the RetryTemplate, ToolCallingManager, and ObservationRegistry objects, I initialized them simply as follows:<\/p>\n<pre class=\"lang:java decode:true \">@Bean\r\nRetryTemplate retryTemplate() {\r\n  return new RetryTemplate();\r\n}\r\n\r\n@Bean\r\nToolCallingManager toolCallingManager() {\r\n  return new ToolCallingManager() {\r\n    @Override\r\n    public List&lt;ToolDefinition&gt; resolveToolDefinitions(ToolCallingChatOptions chatOptions) {\r\n      return List.of();\r\n    }\r\n\r\n    @Override\r\n    public ToolExecutionResult executeToolCalls(Prompt prompt, ChatResponse chatResponse) {\r\n      return null;\r\n    }\r\n  };\r\n}\r\n\r\n@Bean\r\nObservationRegistry observationRegistry() {\r\n  return ObservationRegistry.create();\r\n}<\/pre>\n<p>You can choose <a href=\"https:\/\/platform.openai.com\/docs\/models\" target=\"_blank\" rel=\"noopener\">the OpenAI Model<\/a> you want to use. Here, I&#8217;m declaring the use of the &#8220;<a href=\"https:\/\/platform.openai.com\/docs\/models#o1\" target=\"_blank\" rel=\"noopener\">gpt-5-nano<\/a>&#8221; model with a low cost to save money.<\/p>\n<p>With the above declaration, Spring will automatically initialize the OpenAiApi object, and then the ChatModel interface object, OpenAiChatModel, in the Spring container. We just need to ingest and use it.<\/p>\n<pre class=\"lang:java decode:true \">AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(\r\n    AppConfiguration.class);\r\n\r\nChatModel chatModel = context.getBean(ChatModel.class);<\/pre>\n<p><strong>Now we can use the ChatModel class to query information from OpenAI.<\/strong><\/p>\n<p>Here&#8217;s my example:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springai;\r\n\r\nimport org.springframework.ai.chat.model.ChatModel;\r\nimport org.springframework.ai.chat.model.ChatResponse;\r\nimport org.springframework.ai.chat.prompt.Prompt;\r\nimport org.springframework.context.annotation.AnnotationConfigApplicationContext;\r\n\r\npublic class Application {\r\n\r\n  static void main(String[] args) {\r\n    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(\r\n        AppConfiguration.class);\r\n\r\n    ChatModel chatModel = context.getBean(ChatModel.class);\r\n    ChatResponse chatResponse = chatModel.call(\r\n        new Prompt(\"Do you know about Huong Dan Java website?\"));\r\n    System.out.println(chatResponse.getResult());\r\n  }\r\n\r\n}<\/pre>\n<p>Please check the results yourselves!<\/p>\n<p>My results are as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24984 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2024\/05\/an-introduction-about-spring-ai-5.png\" alt=\"\" width=\"700\" height=\"400\" \/><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-right kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;right&quot;,&quot;id&quot;:&quot;22849&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;4&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;An introduction about Spring AI&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\"><\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Spring AI is a module of Spring that helps us easily work with applications that use AI, integrating with AI providers such as OpenAI, Azure OpenAI, Google Gemini, &#8230; In this tutorial, I will introduce you to all the basic knowledge about Spring AI so&hellip; <a href=\"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":1680,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2392],"tags":[],"class_list":["post-22849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-ai-en","clearfix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>An introduction about Spring AI - Huong Dan Java<\/title>\n<meta name=\"description\" content=\"In this tutorial, I introduce with you all basic about Spring AI to work with AI providers such as OpenAI, Azure OpenAI, Google Gemini, ...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An introduction about Spring AI - Huong Dan Java\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I introduce with you all basic about Spring AI to work with AI providers such as OpenAI, Azure OpenAI, Google Gemini, ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html\" \/>\n<meta property=\"og:site_name\" content=\"Huong Dan Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-26T03:35:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-22T11:56:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2016\/10\/spring-boot.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Khanh Nguyen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/KhanhNguyenJ\" \/>\n<meta name=\"twitter:site\" content=\"@KhanhNguyenJ\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khanh Nguyen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html\"},\"author\":{\"name\":\"Khanh Nguyen\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"headline\":\"An introduction about Spring AI\",\"datePublished\":\"2024-05-26T03:35:39+00:00\",\"dateModified\":\"2025-12-22T11:56:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html\"},\"wordCount\":721,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2016\\\/10\\\/spring-boot.png\",\"articleSection\":[\"Spring AI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html\",\"name\":\"An introduction about Spring AI - Huong Dan Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2016\\\/10\\\/spring-boot.png\",\"datePublished\":\"2024-05-26T03:35:39+00:00\",\"dateModified\":\"2025-12-22T11:56:11+00:00\",\"description\":\"In this tutorial, I introduce with you all basic about Spring AI to work with AI providers such as OpenAI, Azure OpenAI, Google Gemini, ...\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html#primaryimage\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2016\\\/10\\\/spring-boot.png\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2016\\\/10\\\/spring-boot.png\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/an-introduction-about-spring-ai.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/huongdanjava.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"An introduction about Spring AI\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/\",\"name\":\"Huong Dan Java\",\"description\":\"Java development tutorials\",\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/huongdanjava.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\",\"name\":\"Khanh Nguyen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"width\":1267,\"height\":1517,\"caption\":\"Khanh Nguyen\"},\"logo\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\"},\"description\":\"I love Java and everything related to Java.\",\"sameAs\":[\"https:\\\/\\\/huongdanjava.com\",\"https:\\\/\\\/www.facebook.com\\\/nhkhanh2406\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/KhanhNguyenJ\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An introduction about Spring AI - Huong Dan Java","description":"In this tutorial, I introduce with you all basic about Spring AI to work with AI providers such as OpenAI, Azure OpenAI, Google Gemini, ...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html","og_locale":"en_US","og_type":"article","og_title":"An introduction about Spring AI - Huong Dan Java","og_description":"In this tutorial, I introduce with you all basic about Spring AI to work with AI providers such as OpenAI, Azure OpenAI, Google Gemini, ...","og_url":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html","og_site_name":"Huong Dan Java","article_publisher":"https:\/\/www.facebook.com\/nhkhanh2406","article_author":"https:\/\/www.facebook.com\/nhkhanh2406","article_published_time":"2024-05-26T03:35:39+00:00","article_modified_time":"2025-12-22T11:56:11+00:00","og_image":[{"width":300,"height":300,"url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2016\/10\/spring-boot.png","type":"image\/png"}],"author":"Khanh Nguyen","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/KhanhNguyenJ","twitter_site":"@KhanhNguyenJ","twitter_misc":{"Written by":"Khanh Nguyen","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html#article","isPartOf":{"@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html"},"author":{"name":"Khanh Nguyen","@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"headline":"An introduction about Spring AI","datePublished":"2024-05-26T03:35:39+00:00","dateModified":"2025-12-22T11:56:11+00:00","mainEntityOfPage":{"@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html"},"wordCount":721,"commentCount":0,"publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"image":{"@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2016\/10\/spring-boot.png","articleSection":["Spring AI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html","url":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html","name":"An introduction about Spring AI - Huong Dan Java","isPartOf":{"@id":"https:\/\/huongdanjava.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html#primaryimage"},"image":{"@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2016\/10\/spring-boot.png","datePublished":"2024-05-26T03:35:39+00:00","dateModified":"2025-12-22T11:56:11+00:00","description":"In this tutorial, I introduce with you all basic about Spring AI to work with AI providers such as OpenAI, Azure OpenAI, Google Gemini, ...","breadcrumb":{"@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html#primaryimage","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2016\/10\/spring-boot.png","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2016\/10\/spring-boot.png","width":300,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/huongdanjava.com\/an-introduction-about-spring-ai.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/huongdanjava.com\/"},{"@type":"ListItem","position":2,"name":"An introduction about Spring AI"}]},{"@type":"WebSite","@id":"https:\/\/huongdanjava.com\/#website","url":"https:\/\/huongdanjava.com\/","name":"Huong Dan Java","description":"Java development tutorials","publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/huongdanjava.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d","name":"Khanh Nguyen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","width":1267,"height":1517,"caption":"Khanh Nguyen"},"logo":{"@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg"},"description":"I love Java and everything related to Java.","sameAs":["https:\/\/huongdanjava.com","https:\/\/www.facebook.com\/nhkhanh2406","https:\/\/x.com\/https:\/\/twitter.com\/KhanhNguyenJ"]}]}},"_links":{"self":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/22849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/comments?post=22849"}],"version-history":[{"count":6,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/22849\/revisions"}],"predecessor-version":[{"id":24985,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/22849\/revisions\/24985"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media\/1680"}],"wp:attachment":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media?parent=22849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/categories?post=22849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/tags?post=22849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}