{"id":9206,"date":"2026-10-07T17:18:23","date_gmt":"2026-10-07T11:48:23","guid":{"rendered":"https:\/\/newsdata.io\/blog\/?p=9206"},"modified":"2026-10-07T17:18:23","modified_gmt":"2026-10-07T11:48:23","slug":"summarize-news-articles-with-an-llm-api-in-python","status":"publish","type":"post","link":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/","title":{"rendered":"How to Summarize News Articles With an LLM API in Python"},"content":{"rendered":"[vc_row type=&#8221;in_container&#8221; full_screen_row_position=&#8221;middle&#8221; column_margin=&#8221;default&#8221; column_direction=&#8221;default&#8221; column_direction_tablet=&#8221;default&#8221; column_direction_phone=&#8221;default&#8221; scene_position=&#8221;center&#8221; text_color=&#8221;dark&#8221; text_align=&#8221;left&#8221; row_border_radius=&#8221;none&#8221; row_border_radius_applies=&#8221;bg&#8221; overflow=&#8221;visible&#8221; overlay_strength=&#8221;0.3&#8243; gradient_direction=&#8221;left_to_right&#8221; shape_divider_position=&#8221;bottom&#8221; bg_image_animation=&#8221;none&#8221;][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_tablet=&#8221;inherit&#8221; column_padding_phone=&#8221;inherit&#8221; column_padding_position=&#8221;all&#8221; column_element_direction_desktop=&#8221;default&#8221; column_element_spacing=&#8221;default&#8221; desktop_text_alignment=&#8221;default&#8221; tablet_text_alignment=&#8221;default&#8221; phone_text_alignment=&#8221;default&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; column_backdrop_filter=&#8221;none&#8221; column_shadow=&#8221;none&#8221; column_border_radius=&#8221;none&#8221; column_link_target=&#8221;_self&#8221; column_position=&#8221;default&#8221; gradient_direction=&#8221;left_to_right&#8221; overlay_strength=&#8221;0.3&#8243; width=&#8221;1\/4&#8243; tablet_width_inherit=&#8221;default&#8221; animation_type=&#8221;default&#8221; bg_image_animation=&#8221;none&#8221; border_type=&#8221;simple&#8221; column_border_width=&#8221;none&#8221; column_border_style=&#8221;solid&#8221; column_padding_type=&#8221;default&#8221; gradient_type=&#8221;default&#8221; offset=&#8221;vc_hidden-sm vc_hidden-xs&#8221;][\/vc_column][vc_column column_padding=&#8221;no-extra-padding&#8221; column_padding_tablet=&#8221;inherit&#8221; column_padding_phone=&#8221;inherit&#8221; column_padding_position=&#8221;all&#8221; column_element_direction_desktop=&#8221;default&#8221; column_element_spacing=&#8221;default&#8221; desktop_text_alignment=&#8221;default&#8221; tablet_text_alignment=&#8221;default&#8221; phone_text_alignment=&#8221;default&#8221; background_color_opacity=&#8221;1&#8243; background_hover_color_opacity=&#8221;1&#8243; column_backdrop_filter=&#8221;none&#8221; column_shadow=&#8221;none&#8221; column_border_radius=&#8221;none&#8221; column_link_target=&#8221;_self&#8221; column_position=&#8221;default&#8221; el_class=&#8221;text_block_wrapper&#8221; gradient_direction=&#8221;left_to_right&#8221; overlay_strength=&#8221;0.3&#8243; width=&#8221;3\/4&#8243; tablet_width_inherit=&#8221;default&#8221; animation_type=&#8221;default&#8221; bg_image_animation=&#8221;none&#8221; border_type=&#8221;simple&#8221; column_border_width=&#8221;none&#8221; column_border_style=&#8221;solid&#8221; column_padding_type=&#8221;default&#8221; gradient_type=&#8221;default&#8221; offset=&#8221;vc_col-lg-9 vc_col-md-12&#8243;][image_with_animation image_url=&#8221;399&#8243; image_size=&#8221;full&#8221; animation_type=&#8221;entrance&#8221; animation=&#8221;None&#8221; animation_movement_type=&#8221;transform_y&#8221; hover_animation=&#8221;none&#8221; alignment=&#8221;&#8221; border_radius=&#8221;none&#8221; box_shadow=&#8221;none&#8221; image_loading=&#8221;default&#8221; max_width=&#8221;100%&#8221; max_width_mobile=&#8221;default&#8221;][vc_column_text]To summarize news articles with an LLM API in Python, request recent articles from the NewsData.io latest endpoint, send each title and description to a chat completions endpoint with a short instruction, and print the reply. This tutorial builds that script with DeepSeek V4 Pro on <a href=\"https:\/\/aimlapi.com\">AI\/ML API<\/a> in 51 lines.<\/p>\n<p>The script needs only the requests library. Each step below comes with a screenshot of the code and a screenshot of a real run, so you can repeat every action on your own machine.[\/vc_column_text][vc_column_text]\n<h2><b>How the pipeline works<\/b><\/h2>\n<p>The script makes two kinds of HTTP calls. A GET request to https:\/\/newsdata.io\/api\/1\/latest returns a JSON object with a results list. Each item in the list is one article with the fields title, description, link, source_id and pubDate. A POST request to https:\/\/api.aimlapi.com\/v1\/chat\/completions sends the article text to the model and returns the summary in choices[0].message.content.<\/p>\n<p>The script filters out articles that have no description, because there is nothing to summarize in them. It then sends one request per article, so a failed request affects one summary and not the whole batch.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9212 size-full\" src=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170752.661.png?resize=512%2C165&#038;ssl=1\" alt=\"\" width=\"512\" height=\"165\" srcset=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170752.661.png?w=512&amp;ssl=1 512w, https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170752.661.png?resize=300%2C97&amp;ssl=1 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" data-recalc-dims=\"1\" \/><\/p>\n<p style=\"text-align: center\"><em>The four stages of the script.<\/em><\/p>\n[\/vc_column_text][vc_column_text]\n<h2><b>What you need before you start<\/b><\/h2>\n<p>You need four things.<\/p>\n<ul>\n<li>Python 3 with the requests library.<\/li>\n<li>A NewsData.io API key. Register on the NewsData.io sign up page and copy the key from your dashboard.<\/li>\n<li>An AI\/ML API key. Create an account on the AI\/ML API website and generate a key on the API keys page.<\/li>\n<li>A small balance on AI\/ML API. Billing is per token. In the test run for this article, one summary used 154 input tokens and 99 output tokens, which costs about $0.0005 at the DeepSeek V4 Pro prices of $1.17 and $3.51 per 1M tokens.<\/li>\n<\/ul>\n<p>According to the NewsData.io documentation, a free account returns up to 10 articles per request and covers the past 48 hours. That is enough for this tutorial. The script requests 5 articles, so the whole run costs about $0.003 on the AI\/ML API side.<\/p>\n<p>Install the library and store both keys in environment variables. The script reads the keys from the environment, so they never end up in your source code or in a Git repository.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9213 size-full\" src=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170746.945.png?resize=512%2C122&#038;ssl=1\" alt=\"\" width=\"512\" height=\"122\" srcset=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170746.945.png?w=512&amp;ssl=1 512w, https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170746.945.png?resize=300%2C71&amp;ssl=1 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" data-recalc-dims=\"1\" \/><\/p>\n<p>On Windows PowerShell, set a variable with $env:NEWSDATA_KEY=&#8221;your_newsdata_key&#8221; instead of the export command.[\/vc_column_text][vc_column_text]\n<h2><b>Step 1. Set up the keys and the prompt<\/b><\/h2>\n<p>Create a file named news_summary.py. The first block imports the libraries, reads the keys, and defines the two URLs, the model ID and the system prompt.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9214 size-full\" src=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170742.015.png?resize=512%2C204&#038;ssl=1\" alt=\"\" width=\"512\" height=\"204\" srcset=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170742.015.png?w=512&amp;ssl=1 512w, https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170742.015.png?resize=300%2C120&amp;ssl=1 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" data-recalc-dims=\"1\" \/><\/p>\n<p>The system prompt does three jobs. It limits the model to the facts in the text, it fixes the length at 2 sentences, and it forbids opinions and background. A fixed length makes the output easy to compare across articles. A limit to the given facts keeps the model from adding details that the source does not contain.[\/vc_column_text][vc_column_text]\n<h2><b>Step 2. Fetch the latest articles<\/b><\/h2>\n<p>The fetch_articles function sends the key, the search query, the language and the number of articles as URL parameters. The q parameter searches for keywords in the article, and language set to en keeps the results in English. The call to raise_for_status stops the script on any HTTP error, such as a wrong key. The last line keeps only the articles that have a description.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9207 size-full\" src=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170737.152.png?resize=512%2C96&#038;ssl=1\" alt=\"\" width=\"512\" height=\"96\" srcset=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170737.152.png?w=512&amp;ssl=1 512w, https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170737.152.png?resize=300%2C56&amp;ssl=1 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" data-recalc-dims=\"1\" \/>[\/vc_column_text][vc_column_text]\n<h2><b>Step 3. Summarize one article<\/b><\/h2>\n<p>The summarize function joins the title and the description into one text and sends it as the user message, next to the system prompt. The request body follows the OpenAI chat format, so the same code works with other chat models on AI\/ML API after you change the model ID. The function returns the text of the first choice.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9208 size-full\" src=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170731.607.png?resize=512%2C193&#038;ssl=1\" alt=\"\" width=\"512\" height=\"193\" srcset=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170731.607.png?w=512&amp;ssl=1 512w, https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170731.607.png?resize=300%2C113&amp;ssl=1 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" data-recalc-dims=\"1\" \/><\/p>\n<p>The max_tokens value is 400. DeepSeek V4 Pro is a reasoning model, and its reasoning tokens are counted inside the output tokens. In the test run, 68 of the 99 output tokens were reasoning tokens. A very small max_tokens value can leave too little room for the answer, so keep some margin.[\/vc_column_text][vc_column_text]\n<h2><b>Step 4. Print the results and run the script<\/b><\/h2>\n<p>The main function fetches 5 articles about artificial intelligence, summarizes each one and prints the title, the source, the summary and the link.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9209 size-full\" src=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170726.391.png?resize=512%2C124&#038;ssl=1\" alt=\"\" width=\"512\" height=\"124\" srcset=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170726.391.png?w=512&amp;ssl=1 512w, https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170726.391.png?resize=300%2C73&amp;ssl=1 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Run the script.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9210 size-full\" src=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170721.083.png?resize=313%2C73&#038;ssl=1\" alt=\"\" width=\"313\" height=\"73\" srcset=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170721.083.png?w=313&amp;ssl=1 313w, https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170721.083.png?resize=300%2C70&amp;ssl=1 300w\" sizes=\"(max-width: 313px) 100vw, 313px\" data-recalc-dims=\"1\" \/><\/p>\n<p>The output below comes from a real run of this script. The summary of each article appears between its title and its link.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9211 size-full\" src=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170714.816.png?resize=512%2C347&#038;ssl=1\" alt=\"\" width=\"512\" height=\"347\" srcset=\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170714.816.png?w=512&amp;ssl=1 512w, https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2026\/10\/unnamed-2026-10-07T170714.816.png?resize=300%2C203&amp;ssl=1 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" data-recalc-dims=\"1\" \/><\/p>\n<p style=\"text-align: center\"><em>Output of news_summary.py. The model returned two sentences for each article.<\/em><\/p>\n<p>Each summary has exactly 2 sentences, as the system prompt requires. The first sentence often restates the title, because a description is only a few lines long. The summary becomes more useful when you pass the full text of the article instead of the description. In that case, change the first line of the text variable in the summarize function and keep the rest of the code.[\/vc_column_text][vc_column_text]\n<h2><b>Which model to use<\/b><\/h2>\n<p>The script uses the <a href=\"https:\/\/aimlapi.com\/models\/deepseek-v4-pro\">DeepSeek V4 Pro API<\/a> with the model ID deepseek\/deepseek-v4-pro. According to the model page, the context window is 1,000,000 tokens, the maximum output is 384,000 tokens, and the model was released on April 24, 2026. The page lists streaming, structured output, tools and reasoning among the supported parameters.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Item<\/b><\/td>\n<td><b>Value<\/b><\/td>\n<\/tr>\n<tr>\n<td>Model ID<\/td>\n<td>deepseek\/deepseek-v4-pro<\/td>\n<\/tr>\n<tr>\n<td>Context window<\/td>\n<td>1,000,000 tokens<\/td>\n<\/tr>\n<tr>\n<td>Maximum output<\/td>\n<td>384,000 tokens<\/td>\n<\/tr>\n<tr>\n<td>Input price<\/td>\n<td>$1.17 per 1M tokens<\/td>\n<\/tr>\n<tr>\n<td>Output price<\/td>\n<td>$3.51 per 1M tokens<\/td>\n<\/tr>\n<tr>\n<td>Cost of one summary in the test run<\/td>\n<td>About $0.0005<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Verdict for this tutorial. DeepSeek V4 Pro at about $0.0005 per summarized article.<\/b> That figure comes from one request with 154 input tokens and 99 output tokens, so measure your own articles before you plan a budget.<\/p>\n<p>To try another model, replace the value of MODEL with an ID from the <a href=\"https:\/\/aimlapi.com\/models\">AI\/ML API Models<\/a> catalog. Parameters differ between models, so check the model page if a request returns an error.[\/vc_column_text][vc_column_text]\n<h2><b>Common errors and how to handle them<\/b><\/h2>\n<ul>\n<li><b>NewsData.io returns 401. <\/b>The response body reads {&#8220;status&#8221;:&#8221;error&#8221;,&#8221;results&#8221;:{&#8220;message&#8221;:&#8221;The provided API key is not valid.&#8221;,&#8221;code&#8221;:&#8221;Unauthorized&#8221;}}. Check that NEWSDATA_KEY is set in the same terminal session that runs the script.<\/li>\n<li><b>AI\/ML API returns 401. <\/b>The message says that the request requires a valid API key and points to the API keys page. Check AIMLAPI_KEY in the same way.<\/li>\n<li><b>The script prints nothing. <\/b>The query returned no articles with a description. Use a broader query or remove the language parameter.<\/li>\n<li><b>A summary looks cut off. <\/b>Raise the max_tokens value, because reasoning tokens use part of it.<\/li>\n<\/ul>\n<p>Do not remove the timeout argument from the requests calls. Without it, a stalled connection blocks the script forever.[\/vc_column_text][vc_column_text]\n<h2><b>Summary<\/b><\/h2>\n<ul>\n<li>Get articles from the NewsData.io latest endpoint and keep those with a description.<\/li>\n<li>Send the title and the description to the chat completions endpoint with a system prompt that fixes the length.<\/li>\n<li>One summary used 154 input and 99 output tokens, about $0.0005 with DeepSeek V4 Pro.<\/li>\n<li>Keep both API keys in environment variables.<\/li>\n<\/ul>\n[\/vc_column_text][vc_column_text]\n<h2><b>FAQ<\/b><\/h2>\n<h3><b>What is a news summarization API?<\/b><\/h3>\n<p>A news summarization API turns news text into a short summary. In this tutorial, two services work together. A news API such as NewsData.io supplies the articles, and a language model behind a chat completions endpoint writes the summary. You can swap either part without changing the other.<\/p>\n<h3><b>How to summarize news articles with Python?<\/b><\/h3>\n<p>Fetch articles with a GET request to a news API, then send the title and text of each article to a chat completions endpoint with a prompt that asks for a summary of a fixed length. Read the answer from choices[0].message.content. The script in this article does this in 51 lines.<\/p>\n<h3><b>How much does it cost to summarize news with an LLM API?<\/b><\/h3>\n<p>Billing is per token. In the test run for this article, one summary used 154 input tokens and 99 output tokens. At the DeepSeek V4 Pro prices of $1.17 and $3.51 per 1M tokens, that is about $0.0005 per article. Longer articles use more input tokens.<\/p>\n<h3><b>How to get a NewsData.io API key?<\/b><\/h3>\n<p>Register on the NewsData.io sign up page and copy the API key from your dashboard. The key goes into the apikey parameter of every request. According to the NewsData.io documentation, a free account returns up to 10 articles per request and covers the past 48 hours.<\/p>\n<h3><b>How to get an AI\/ML API key?<\/b><\/h3>\n<p>Create an account on AI\/ML API and generate a key on the API keys page. Send it in the Authorization header as a Bearer token. Store it in an environment variable such as AIMLAPI_KEY and never write it into source code.<\/p>\n<h3><b>Can I use a different model for news summaries?<\/b><\/h3>\n<p>Yes. The request follows the chat completions format, so you change only the model ID in the MODEL constant. Pick an ID from the AI\/ML API model catalog. Parameters such as max_tokens can behave differently between models, so check the model page after the switch.[\/vc_column_text][\/vc_column][\/vc_row]\n","protected":false},"excerpt":{"rendered":"<p>To summarize news articles with an LLM API in Python, request recent articles from the NewsData.io latest endpoint, send each title and description to a chat completions endpoint with a short instruction, and print the reply. This tutorial builds that script with DeepSeek V4 Pro on AI\/ML API in 51 lines.<\/p>\n","protected":false},"author":11,"featured_media":399,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Summarize News Articles With an LLM API in Python<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Summarize News Articles With an LLM API in Python\" \/>\n<meta property=\"og:description\" content=\"To summarize news articles with an LLM API in Python, request recent articles from the NewsData.io latest endpoint, send each title and description to a chat completions endpoint with a short instruction, and print the reply. This tutorial builds that script with DeepSeek V4 Pro on AI\/ML API in 51 lines.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Newsdata.io - Stay Updated with the Latest News API Trends\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-07T11:48:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2240\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Raghav Sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Raghav Sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/\",\"url\":\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/\",\"name\":\"How to Summarize News Articles With an LLM API in Python\",\"isPartOf\":{\"@id\":\"https:\/\/newsdata.io\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg?fit=2240%2C1260&ssl=1\",\"datePublished\":\"2026-10-07T11:48:23+00:00\",\"dateModified\":\"2026-10-07T11:48:23+00:00\",\"author\":{\"@id\":\"https:\/\/newsdata.io\/blog\/#\/schema\/person\/2c7fdfa00a8bc73559748ec23250f501\"},\"breadcrumb\":{\"@id\":\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg?fit=2240%2C1260&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg?fit=2240%2C1260&ssl=1\",\"width\":2240,\"height\":1260,\"caption\":\"What is News API blog banner\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/newsdata.io\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Summarize News Articles With an LLM API in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/newsdata.io\/blog\/#website\",\"url\":\"https:\/\/newsdata.io\/blog\/\",\"name\":\"Newsdata.io - Stay Updated with the Latest News API Trends\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/newsdata.io\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/newsdata.io\/blog\/#\/schema\/person\/2c7fdfa00a8bc73559748ec23250f501\",\"name\":\"Raghav Sharma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/newsdata.io\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c64fa1d6e5c1d3bb3076c1db38e95026?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c64fa1d6e5c1d3bb3076c1db38e95026?s=96&d=mm&r=g\",\"caption\":\"Raghav Sharma\"},\"description\":\"Raghav Sharma is a content writer and media researcher at Newsdata.io, specializing in news industry analysis, media literacy, and the evolving landscape of digital journalism. With a background in English Literature and Journalism, along with a focus on fact-based reporting standards, Raghav covers topics including news API technology, editorial bias evaluation, and responsible information consumption. Raghav's work has covered media trends across categories, including healthcare news, international journalism, and API-driven publishing. You can connect with him on LinkedIn or explore more of his writing on the Newsdata.io blog.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/raghav-sharma-4981b4232\/\"],\"url\":\"https:\/\/newsdata.io\/blog\/author\/raghav\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Summarize News Articles With an LLM API in Python","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:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Summarize News Articles With an LLM API in Python","og_description":"To summarize news articles with an LLM API in Python, request recent articles from the NewsData.io latest endpoint, send each title and description to a chat completions endpoint with a short instruction, and print the reply. This tutorial builds that script with DeepSeek V4 Pro on AI\/ML API in 51 lines.","og_url":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/","og_site_name":"Newsdata.io - Stay Updated with the Latest News API Trends","article_published_time":"2026-10-07T11:48:23+00:00","og_image":[{"width":2240,"height":1260,"url":"https:\/\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg","type":"image\/jpeg"}],"author":"Raghav Sharma","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Raghav Sharma","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/","url":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/","name":"How to Summarize News Articles With an LLM API in Python","isPartOf":{"@id":"https:\/\/newsdata.io\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#primaryimage"},"image":{"@id":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg?fit=2240%2C1260&ssl=1","datePublished":"2026-10-07T11:48:23+00:00","dateModified":"2026-10-07T11:48:23+00:00","author":{"@id":"https:\/\/newsdata.io\/blog\/#\/schema\/person\/2c7fdfa00a8bc73559748ec23250f501"},"breadcrumb":{"@id":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#primaryimage","url":"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg?fit=2240%2C1260&ssl=1","contentUrl":"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg?fit=2240%2C1260&ssl=1","width":2240,"height":1260,"caption":"What is News API blog banner"},{"@type":"BreadcrumbList","@id":"https:\/\/newsdata.io\/blog\/summarize-news-articles-with-an-llm-api-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/newsdata.io\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Summarize News Articles With an LLM API in Python"}]},{"@type":"WebSite","@id":"https:\/\/newsdata.io\/blog\/#website","url":"https:\/\/newsdata.io\/blog\/","name":"Newsdata.io - Stay Updated with the Latest News API Trends","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/newsdata.io\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/newsdata.io\/blog\/#\/schema\/person\/2c7fdfa00a8bc73559748ec23250f501","name":"Raghav Sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/newsdata.io\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c64fa1d6e5c1d3bb3076c1db38e95026?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c64fa1d6e5c1d3bb3076c1db38e95026?s=96&d=mm&r=g","caption":"Raghav Sharma"},"description":"Raghav Sharma is a content writer and media researcher at Newsdata.io, specializing in news industry analysis, media literacy, and the evolving landscape of digital journalism. With a background in English Literature and Journalism, along with a focus on fact-based reporting standards, Raghav covers topics including news API technology, editorial bias evaluation, and responsible information consumption. Raghav's work has covered media trends across categories, including healthcare news, international journalism, and API-driven publishing. You can connect with him on LinkedIn or explore more of his writing on the Newsdata.io blog.","sameAs":["https:\/\/www.linkedin.com\/in\/raghav-sharma-4981b4232\/"],"url":"https:\/\/newsdata.io\/blog\/author\/raghav\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg?fit=2240%2C1260&ssl=1","category":["API"],"featured_image_url":"https:\/\/i0.wp.com\/newsdata.io\/blog\/wp-content\/uploads\/2021\/05\/news-API.jpg?fit=2240%2C1260&ssl=1","_links":{"self":[{"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/posts\/9206"}],"collection":[{"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/comments?post=9206"}],"version-history":[{"count":3,"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/posts\/9206\/revisions"}],"predecessor-version":[{"id":9217,"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/posts\/9206\/revisions\/9217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/media\/399"}],"wp:attachment":[{"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/media?parent=9206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/categories?post=9206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/newsdata.io\/blog\/wp-json\/wp\/v2\/tags?post=9206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}