<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jieming Liang</title>
    <description>The latest articles on DEV Community by Jieming Liang (@jieming_liang).</description>
    <link>https://dev.to/jieming_liang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3973718%2Fe43876f9-f0f4-4b1c-935f-8e99c94c00ad.png</url>
      <title>DEV Community: Jieming Liang</title>
      <link>https://dev.to/jieming_liang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jieming_liang"/>
    <language>en</language>
    <item>
      <title>How to Use the DeepSeek API in Python — A Beginner's Guide (2026)</title>
      <dc:creator>Jieming Liang</dc:creator>
      <pubDate>Mon, 08 Jun 2026 09:08:41 +0000</pubDate>
      <link>https://dev.to/jieming_liang/how-to-use-the-deepseek-api-in-python-a-beginners-guide-2026-fne</link>
      <guid>https://dev.to/jieming_liang/how-to-use-the-deepseek-api-in-python-a-beginners-guide-2026-fne</guid>
      <description>&lt;p&gt;Everyone keeps saying "DeepSeek is so cheap," but most tutorials jump straight into the advanced stuff. So here's the version I wish I'd had on day one — from zero to your first working API call, no prior experience needed.&lt;/p&gt;

&lt;p&gt;Two reasons DeepSeek is a great first API to learn on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;It's cheap.&lt;/strong&gt; Like, an order of magnitude cheaper than the big US models. You can experiment all day without watching a meter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It's OpenAI-compatible.&lt;/strong&gt; If you've ever seen OpenAI's Python code, you already know how to use this — you change two lines. So the skill transfers everywhere.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's get you a working call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 — Get your API key
&lt;/h2&gt;

&lt;p&gt;Go to &lt;a href="https://platform.deepseek.com" rel="noopener noreferrer"&gt;platform.deepseek.com&lt;/a&gt;, sign up, open the &lt;strong&gt;API Keys&lt;/strong&gt; page, and create a new key. Copy it right away — you only see it once. Then save it as an environment variable instead of pasting it into your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;DEEPSEEK_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your_key_here"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Never hardcode a key into a file you might push to GitHub. People scrape for leaked keys.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 — Install the SDK
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;openai
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, the &lt;em&gt;OpenAI&lt;/em&gt; SDK. DeepSeek speaks the same protocol, so we reuse it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 — Your first call
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DEEPSEEK_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.deepseek.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;deepseek-v4-flash&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;system&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are a helpful assistant.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Explain what an API is in one sentence.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. The only things that make this "DeepSeek" instead of "OpenAI" are the &lt;code&gt;base_url&lt;/code&gt; and the &lt;code&gt;model&lt;/code&gt;. Everything else is identical.&lt;/p&gt;

&lt;h2&gt;
  
  
  Not a Python person? (curl)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.deepseek.com/chat/completions &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer &lt;/span&gt;&lt;span class="nv"&gt;$DEEPSEEK_API_KEY&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
    "model": "deepseek-v4-flash",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The part that surprised me: the price
&lt;/h2&gt;

&lt;p&gt;DeepSeek V4 Flash runs about &lt;strong&gt;$0.14 per million input tokens&lt;/strong&gt; and &lt;strong&gt;$0.28 per million output tokens&lt;/strong&gt;. A million tokens is roughly 750,000 words. So a full day of heavy experimenting costs you cents, not dollars.&lt;/p&gt;

&lt;p&gt;For comparison, the flagship GPT and Claude models can cost 10x+ that on output. For learning, side projects, and honestly most production workloads, the cheap tier is genuinely good enough. (Cache hits are billed at 1/10 the input price, which adds up fast if you reuse prompts.)&lt;/p&gt;

&lt;h2&gt;
  
  
  A few beginner gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use the model name &lt;code&gt;deepseek-v4-flash&lt;/code&gt;.&lt;/strong&gt; The old &lt;code&gt;deepseek-chat&lt;/code&gt; alias still works but is being retired on &lt;strong&gt;July 24, 2026&lt;/strong&gt; — a lot of older tutorials still use it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You need to add a little credit before it works.&lt;/strong&gt; There's no unlimited free tier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"OpenAI-compatible" ≠ OpenAI.&lt;/strong&gt; A few niche parameters differ, but the basics above are identical.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep your key out of git.&lt;/strong&gt; Worth saying twice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;You now have a working, dirt-cheap AI API and code that transfers to almost any other model. Go build something.&lt;/p&gt;

&lt;p&gt;What are you making with it? And if you're outside the US — &lt;strong&gt;was getting set up easy, or was payment/signup the hard part?&lt;/strong&gt; Curious how common that is.&lt;/p&gt;

</description>
      <category>deepseek</category>
      <category>python</category>
      <category>ai</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
