<?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: kaixiaocoding</title>
    <description>The latest articles on DEV Community by kaixiaocoding (@kaixiaocoding).</description>
    <link>https://dev.to/kaixiaocoding</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4178217%2Fde9a25eb-49a8-44e8-857b-5564cac7afb3.png</url>
      <title>DEV Community: kaixiaocoding</title>
      <link>https://dev.to/kaixiaocoding</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kaixiaocoding"/>
    <language>en</language>
    <item>
      <title>An API for open-weight AI models: what to check, and how to call one with the OpenAI or Anthropic SDK</title>
      <dc:creator>kaixiaocoding</dc:creator>
      <pubDate>Mon, 12 Oct 2026 03:47:37 +0000</pubDate>
      <link>https://dev.to/kaixiaocoding/an-api-for-open-weight-ai-models-what-to-check-and-how-to-call-one-with-the-openai-or-anthropic-g98</link>
      <guid>https://dev.to/kaixiaocoding/an-api-for-open-weight-ai-models-what-to-check-and-how-to-call-one-with-the-openai-or-anthropic-g98</guid>
      <description>&lt;p&gt;Open-weight models — models whose trained weights are published for anyone to download — are now good enough for a lot of everyday work: coding agents, tool use, extraction, summarising. The hard part is no longer the model. It is running it. This post covers the three ways to use an open-weight model, what to check before you pick a hosted API, and the few lines of code it takes to call one from the SDKs you already use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open-weight is not the same as open source
&lt;/h2&gt;

&lt;p&gt;"Open-weight" means the weights are public. It does not automatically mean the training data, the training code or a permissive licence are public too. Licences range from MIT and Apache 2.0 to custom licences with usage limits, so read the model card before you build a product on one. For calling a model through an API, what matters is that anyone can serve it — which is why the same open-weight model is often available from several providers at different prices and speeds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three ways to run an open-weight model
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run it yourself.&lt;/strong&gt; Tools such as vLLM, SGLang, llama.cpp or Ollama expose an OpenAI-compatible endpoint on your own machine or GPU server. Full control, but you pay for the hardware whether you use it or not, and a 30B-class model needs a serious GPU.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rent dedicated GPUs.&lt;/strong&gt; Someone else runs the hardware; you still pay per hour, busy or idle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Call a hosted, pay-per-token API.&lt;/strong&gt; You send requests and pay for the tokens you use. Nothing to run, nothing to pay while idle. For most teams trying open models, this is the place to start.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What to check in a hosted API
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Protocol compatibility.&lt;/strong&gt; If the API speaks OpenAI Chat Completions (and ideally the Anthropic Messages protocol), your existing code and tools work after changing the base URL, the key and the model id.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Precision.&lt;/strong&gt; Providers may serve the same model at full precision (BF16) or with quantized weights (FP8, 4-bit). Quantization makes serving cheaper and can change output quality slightly. A good provider tells you which precision each model runs at.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context window and max output&lt;/strong&gt; per model — they are not always the lab's maximum.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tool calling and reasoning controls.&lt;/strong&gt; Agents depend on reliable tool calls; reasoning models let you turn thinking down or off for simple tasks, which saves output tokens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prices per token&lt;/strong&gt; for input, output and cached input. Cached input matters for agents, which resend long prompts on every step.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data handling.&lt;/strong&gt; Does the provider store request content? Use it for training? Read the privacy page, not the landing page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measured performance.&lt;/strong&gt; Time to first token and tokens per second, measured and published, beat "blazing fast" in a headline.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Calling one: the code
&lt;/h2&gt;

&lt;p&gt;The example below uses &lt;a href="https://www.tokener.ca" rel="noopener noreferrer"&gt;Tokener CA&lt;/a&gt;, a pay-as-you-go API for a short, curated list of open-weight models (I work on it — see the note at the end). The same pattern works with any provider that speaks these protocols. Keep the key and the model id in environment variables; model ids are listed on the &lt;a href="https://www.tokener.ca/models" rel="noopener noreferrer"&gt;models page&lt;/a&gt;.&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;TOKENER_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your-api-key"&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;TOKENER_MODEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"a-model-id-from-the-models-page"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  OpenAI SDK (Chat Completions)
&lt;/h3&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TOKENER_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://a.tokener.ca/v1&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;resp&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="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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TOKENER_MODEL&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="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 open-weight models 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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resp&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;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# input, output and cached tokens: what you are billed for
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Streaming (&lt;code&gt;stream=True&lt;/code&gt;), function tools and JSON output carry over unchanged. For usage on a streamed response, pass &lt;code&gt;stream_options={"include_usage": True}&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Anthropic SDK (Messages)
&lt;/h3&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;import&lt;/span&gt; &lt;span class="n"&gt;anthropic&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;anthropic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Anthropic&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TOKENER_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://a.tokener.ca&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;# no /v1: the SDK adds it
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;message&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;messages&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="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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TOKENER_MODEL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;max_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;# required by the Messages protocol
&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="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 open-weight models 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="nf"&gt;print&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;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  curl
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://a.tokener.ca/v1/chat/completions &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;$TOKENER_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;-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;-d&lt;/span&gt; &lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;model&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$TOKENER_MODEL&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;messages&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: [{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;role&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;}]}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using it from tools instead of code
&lt;/h2&gt;

&lt;p&gt;Most AI tools have an "OpenAI-compatible provider" or "custom base URL" setting, and the same three values (base URL, key, model id) are all they need. Step-by-step guides: &lt;a href="https://www.tokener.ca/docs/claude-code" rel="noopener noreferrer"&gt;Claude Code&lt;/a&gt; (through the Anthropic-compatible endpoint), &lt;a href="https://www.tokener.ca/docs/opencode" rel="noopener noreferrer"&gt;OpenCode&lt;/a&gt;, &lt;a href="https://www.tokener.ca/docs/cline" rel="noopener noreferrer"&gt;Cline&lt;/a&gt;, &lt;a href="https://www.tokener.ca/docs/litellm" rel="noopener noreferrer"&gt;LiteLLM&lt;/a&gt;, &lt;a href="https://www.tokener.ca/docs/vercel-ai-sdk" rel="noopener noreferrer"&gt;Vercel AI SDK&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  A sensible way to start
&lt;/h2&gt;

&lt;p&gt;Do not move everything at once. Pick one well-understood task — a first-pass code review, ticket summaries, field extraction — and send it to an open-weight model for a week. Compare the outputs and the bill. If you do not want to write code first, a browser playground lets you try each model and see what a request costs (&lt;a href="https://www.tokener.ca/docs/quickstart" rel="noopener noreferrer"&gt;quickstart without code&lt;/a&gt;).&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Disclosure: I work on Tokener CA, the API used in the examples. It is operated by ShowKey Information Systems Inc., a company incorporated in Ontario, Canada. Each model's price, context window, precision and measured performance are on its page at &lt;a href="https://www.tokener.ca/models" rel="noopener noreferrer"&gt;tokener.ca/models&lt;/a&gt;; the full API reference is at &lt;a href="https://www.tokener.ca/docs/api-reference" rel="noopener noreferrer"&gt;tokener.ca/docs/api-reference&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>opensource</category>
      <category>llm</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
