<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[HeFu AI Blog]]></title><description><![CDATA[Explore multi-model AI APIs, office tools, enterprise solutions and developer tutorials with HeFu. Practical guides for developers and businesses in Malaysia.]]></description><link>https://hefuai.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6ad9836f217fe726b40775aa/f02db00a-d27f-4d49-9c0a-7048f3ac3c31.png</url><title>HeFu AI Blog</title><link>https://hefuai.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 04 Nov 2026 15:50:40 GMT</lastBuildDate><atom:link href="https://hefuai.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Build a Model-Switchable Python CLI with an OpenAI-Compatible API]]></title><description><![CDATA[Build a Python CLI that switches AI models, streams responses, handles API errors, and reports token usage with an OpenAI-compatible endpoint.]]></description><link>https://hefuai.hashnode.dev/build-a-model-switchable-python-cli-with-an-openai-compatible-api</link><guid isPermaLink="true">https://hefuai.hashnode.dev/build-a-model-switchable-python-cli-with-an-openai-compatible-api</guid><category><![CDATA[Python]]></category><category><![CDATA[api]]></category><category><![CDATA[cli]]></category><category><![CDATA[Artificial Intelligence]]></category><dc:creator><![CDATA[HeFuAI]]></dc:creator><pubDate>Fri, 30 Oct 2026 07:00:02 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ad9836f217fe726b40775aa/ad379f5c-af57-421e-b8a4-91d188bb3fe5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>An OpenAI-compatible chat API lets one Python client call different models by changing the <code>model</code> field. That is useful when you want to compare outputs or use a faster model for routine prompts without changing the rest of your application.</p>
<p>In this tutorial, we'll build a command-line tool that accepts a prompt, selects a model, optionally streams the answer, and reports token usage for non-streaming calls. We'll also handle common network and API errors.</p>
<h2>Prerequisites</h2>
<p>You'll need Python 3.9 or newer, an API key for an OpenAI-compatible chat endpoint, and the <code>openai</code> Python package:</p>
<pre><code class="language-bash">python -m pip install --upgrade openai
</code></pre>
<p>Set your API key and base URL as environment variables. The base URL should end at the API version prefix; the SDK adds <code>/chat/completions</code> itself.</p>
<p>On macOS or Linux:</p>
<pre><code class="language-bash">export AI_API_KEY="your-api-key"
export AI_BASE_URL="https://hefu.hk/api/v1"
</code></pre>
<p>On PowerShell:</p>
<pre><code class="language-powershell">$env:AI_API_KEY = "your-api-key"
$env:AI_BASE_URL = "https://hefu.hk/api/v1"
</code></pre>
<h2>Build the CLI</h2>
<p>Save this as <code>model_cli.py</code>:</p>
<pre><code class="language-python">import argparse
import os
import sys

from openai import APIConnectionError, APIStatusError, APITimeoutError, OpenAI


def parse_args() -&gt; argparse.Namespace:
    parser = argparse.ArgumentParser(
        description="Send a prompt to an OpenAI-compatible chat API."
    )
    parser.add_argument("prompt", nargs="+", help="Text to send to the model")
    parser.add_argument(
        "--model",
        default="deepseek-v4-flash",
        help="Model ID supported by your API endpoint",
    )
    parser.add_argument(
        "--system",
        default="You are a helpful assistant.",
        help="System instruction",
    )
    parser.add_argument(
        "--stream",
        action="store_true",
        help="Print response chunks as they arrive",
    )
    return parser.parse_args()


def main() -&gt; int:
    args = parse_args()
    api_key = os.getenv("AI_API_KEY")
    base_url = os.getenv("AI_BASE_URL")

    if not api_key or not base_url:
        print("Set AI_API_KEY and AI_BASE_URL first.", file=sys.stderr)
        return 2

    client = OpenAI(
        api_key=api_key,
        base_url=base_url,
        timeout=30.0,
        max_retries=2,
    )
    messages = [
        {"role": "system", "content": args.system},
        {"role": "user", "content": " ".join(args.prompt)},
    ]

    try:
        if args.stream:
            stream = client.chat.completions.create(
                model=args.model,
                messages=messages,
                stream=True,
            )
            for chunk in stream:
                if not chunk.choices:
                    continue
                text = chunk.choices[0].delta.content
                if text:
                    print(text, end="", flush=True)
            print()
        else:
            response = client.chat.completions.create(
                model=args.model,
                messages=messages,
            )
            print(response.choices[0].message.content or "")
            if response.usage:
                print(
                    f"\nTokens: input={response.usage.prompt_tokens}, "
                    f"output={response.usage.completion_tokens}",
                    file=sys.stderr,
                )
    except APITimeoutError:
        print("Request timed out.", file=sys.stderr)
        return 1
    except APIConnectionError as exc:
        print(f"Connection error: {exc}", file=sys.stderr)
        return 1
    except APIStatusError as exc:
        print(f"API error (HTTP {exc.status_code}): {exc.message}", file=sys.stderr)
        return 1

    return 0


if __name__ == "__main__":
    raise SystemExit(main())
</code></pre>
<h2>Run it</h2>
<p>The default model ID in this example matches the sample endpoint above:</p>
<pre><code class="language-bash">python model_cli.py "Explain what an API gateway does in two sentences."
</code></pre>
<p>Choose another model ID that your endpoint supports without editing the Python file:</p>
<pre><code class="language-bash">python model_cli.py --model YOUR_OTHER_MODEL_ID "Summarize the purpose of unit tests."
</code></pre>
<p>Stream a longer answer:</p>
<pre><code class="language-bash">python model_cli.py --stream "Explain the difference between retries and timeouts."
</code></pre>
<p>The second command contains a placeholder. Replace <code>YOUR_OTHER_MODEL_ID</code> with an actual ID listed by your API provider.</p>
<h2>Why the two response paths differ</h2>
<p>Without <code>--stream</code>, <code>create()</code> returns one completed response. We can read <code>response.choices[0].message.content</code> and, when provided, <code>response.usage</code>.</p>
<p>With <code>--stream</code>, the call yields chunks. Each chunk can contain new text in <code>choices[0].delta.content</code>. Some chunks contain no text, so we check before printing. This basic streaming example does not request usage data; if you need streaming usage, check whether your provider supports the relevant <code>stream_options</code> behavior.</p>
<h2>Common failure cases</h2>
<table>
<thead>
<tr>
<th>Symptom</th>
<th>What to check</th>
</tr>
</thead>
<tbody><tr>
<td>401 or 403</td>
<td>Confirm the key and its permissions.</td>
</tr>
<tr>
<td>404 or model error</td>
<td>Check the base URL and exact model ID.</td>
</tr>
<tr>
<td>429</td>
<td>Reduce request rate or handle the provider's quota limits.</td>
</tr>
<tr>
<td>Timeout</td>
<td>Try a shorter prompt or increase the client timeout.</td>
</tr>
</tbody></table>
<p>Keep the API key in an environment variable and avoid printing it in logs. For production use, add application-specific retry policies, structured logs, and request tracing.</p>
<p>If you adapted this code for your own endpoint, which part would you change first: model selection, output formatting, or error handling?</p>
<p>Disclosure: This article was drafted with AI assistance.</p>
]]></content:encoded></item><item><title><![CDATA[Introducing HeFu: Multi-Model AI APIs and Practical Tools for Business]]></title><description><![CDATA[Explore HeFu's multi-model AI API, office agents, enterprise solutions, and developer platform for building apps and simplifying everyday work.]]></description><link>https://hefuai.hashnode.dev/introducing-hefu-multi-model-ai-apis-and-practical-tools-for-business</link><guid isPermaLink="true">https://hefuai.hashnode.dev/introducing-hefu-multi-model-ai-apis-and-practical-tools-for-business</guid><category><![CDATA[artificial ]]></category><category><![CDATA[api]]></category><category><![CDATA[Developer Tools]]></category><category><![CDATA[SaaS]]></category><category><![CDATA[automation]]></category><dc:creator><![CDATA[HeFuAI]]></dc:creator><pubDate>Thu, 22 Oct 2026 05:18:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ad9836f217fe726b40775aa/396fb8be-1b7e-44d2-a82e-2edf65415242.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Building an AI feature and using AI in everyday work involve different needs. A developer may want to test multiple models through an API. An e-commerce seller may need product descriptions and customer support drafts. A business team may need a more organized way to manage AI access.</p>
<p>We’re the team behind HeFu. In this first post, we’ll introduce the four parts of our platform and show how they fit into practical workflows for developers and businesses, including teams in Malaysia.</p>
<p><strong>1. Model aggregation: access multiple models through one API</strong></p>
<p>Managing separate integrations can make experimentation more complicated. Each additional provider may introduce another API key, billing account and integration to maintain.</p>
<p>HeFu brings multiple AI models together through an OpenAI-compatible API, with a single API key and centralized usage and billing.</p>
<p>For developers, this provides a common starting point for comparing models and choosing one for a specific task. API usage follows a prepaid model: users top up their balance, and charges are deducted according to usage.</p>
<p>A useful way to evaluate models is to test the same small set of representative tasks across your candidates. Compare factual accuracy, instruction following, response time and usage cost. API compatibility simplifies integration, but individual models can still differ in supported features and parameters.</p>
<p><strong>2. Office tools: turn business inputs into useful drafts</strong></p>
<p>Not every task needs a custom integration. HeFu’s office tools include a Seller Assistant for common e-commerce workflows:</p>
<ul>
<li><p>Amazon listing drafts, including titles, bullet points and backend search terms.</p>
</li>
<li><p>A+ content copy for brand stories and product presentation modules.</p>
</li>
<li><p>Shopify product page copy, including SEO titles and meta descriptions.</p>
</li>
<li><p>Customer support reply drafts based on buyer messages and order context.</p>
</li>
<li><p>Buyer review analysis to identify recurring complaints and product strengths.</p>
</li>
</ul>
<p>For example, a seller preparing a new product page can start with verified specifications, the intended audience and the product’s main benefits. These inputs provide a stronger foundation than a short instruction such as “write a good listing.”</p>
<p>Before publishing, review generated copy for accuracy, unsupported claims and the requirements of the marketplace you use.</p>
<p><strong>3. Enterprise services: organize AI use across teams</strong></p>
<p>As AI adoption expands, businesses may need to coordinate access across teams or support different customer groups.</p>
<p>HeFu’s enterprise offering includes options for team access, centralized management and multi-tenant use. The appropriate setup depends on how the business plans to organize users and deliver its services.</p>
<p>A useful starting point is to define who needs access, which workflows they will use and whether different teams or customers require separate environments.</p>
<p><strong>4. Developer platform: connect AI to your own workflows</strong></p>
<p>The developer platform provides APIs and resources for integrating AI into applications, websites and business processes.</p>
<p>One example is a product content workflow: collect verified product information, request a draft, send it for human review, and publish the approved version. This keeps AI generation connected to an actual business process.</p>
<p>Start with one task and a clear success criterion before expanding the integration.</p>
<p><strong>What we’ll share next</strong></p>
<p>This blog will cover API integration tutorials, model evaluation methods and practical AI workflows for sellers and business teams.</p>
<p>What are you working on: a multi-model application, an e-commerce workflow or an internal AI tool? We’d welcome your questions and feedback.</p>
]]></content:encoded></item></channel></rss>