<?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[CheapClankers Developer Guides]]></title><description><![CDATA[CheapClankers Developer Guides]]></description><link>https://cheapclankers.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 21:25:52 GMT</lastBuildDate><atom:link href="https://cheapclankers.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Haystack with a custom OpenAI API base URL: check models before chat]]></title><description><![CDATA[Configure Haystack OpenAIChatGenerator with a custom endpoint, check model access, and reproduce four local fixture checks before paid inference.]]></description><link>https://cheapclankers.hashnode.dev/haystack-with-a-custom-openai-api-base-url-check-models-before-chat</link><guid isPermaLink="true">https://cheapclankers.hashnode.dev/haystack-with-a-custom-openai-api-base-url-check-models-before-chat</guid><category><![CDATA[Python]]></category><category><![CDATA[haystack]]></category><dc:creator><![CDATA[CheapClankers]]></dc:creator><pubDate>Wed, 18 Nov 2026 21:20:20 GMT</pubDate><content:encoded><![CDATA[<p>Disclosure: CheapClankers operates the paid API used in this example. This article was prepared with AI. The companion program was tested against a local mock API, not production inference. No endorsement by Haystack or OpenAI is implied.</p>
<p>Haystack's <code>OpenAIChatGenerator</code> accepts a custom <code>api_base_url</code>. That is useful when your application uses a service with an OpenAI-compatible Chat Completions endpoint. It does not mean every model or feature at that endpoint will work with every Haystack component.</p>
<p>Our <a href="https://github.com/MacFinn/cheapclankers-examples/tree/main/python-integrations">public Python integration example</a> separates model discovery from generation. It checks whether the key can see the chosen model before constructing the generator. That gives you a smaller problem to debug when setting up a new endpoint.</p>
<h2>Configure the base, model and credential separately</h2>
<p>Create a Python 3.11 environment, then install the example's pinned dependencies:</p>
<pre><code class="language-sh">git clone https://github.com/MacFinn/cheapclankers-examples.git
cd cheapclankers-examples/python-integrations
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
</code></pre>
<p>The example pins <code>haystack-ai==3.5.0</code> and <code>litellm==1.110.0</code>. LiteLLM supports the second client in the same fixture; it is not needed to understand the Haystack configuration.</p>
<p>For the real endpoint, set server-side environment variables. In Bash or zsh:</p>
<pre><code class="language-sh">export CLANKER_API_KEY="your_key_here"
export CLANKER_MODEL="your_enabled_chat_model_id"
export CLANKER_BASE_URL="https://api.cheapclankers.com/v1"
python chat.py haystack
</code></pre>
<p>On Windows PowerShell, activate with <code>.\.venv\Scripts\Activate.ps1</code> and assign variables using <code>$env:CLANKER_MODEL = "your_enabled_chat_model_id"</code>, with the same syntax for the key and base URL.</p>
<p>Use an exact model ID from the current <a href="https://cheapclankers.com/models">model catalogue</a>, and check that it supports Chat Completions. Keep credentials out of browser code, source control and copied error reports. Running the real chat command consumes prepaid API credit.</p>
<h2>Know which path the generator will construct</h2>
<p>The base ends at <code>/v1</code>; do not append <code>/chat/completions</code> yourself. The example first requests <code>GET /v1/models</code> using the key. If the selected ID is absent, it exits without sending a generation request.</p>
<p>The central Haystack configuration is:</p>
<pre><code class="language-python">generator = OpenAIChatGenerator(
    model=model,
    api_base_url=base,
    api_key=Secret.from_token(key),
    generation_kwargs={"max_tokens": 64},
    timeout=30,
    max_retries=0,
)
reply = generator.run([ChatMessage.from_user(prompt)])["replies"][0].text
</code></pre>
<p>The complete source includes the imports, environment handling and discovery gate. The <a href="https://docs.haystack.deepset.ai/docs/openaichatgenerator">official OpenAIChatGenerator documentation</a> describes the component and its configuration options.</p>
<p>An accessible model can still reject a particular request. Protocol support, provider availability, tool calling, streaming and model-specific token parameters are separate concerns. This example checks one non-streaming text request only.</p>
<h2>Reproduce the local check before spending credit</h2>
<p>From the integration directory, run:</p>
<pre><code class="language-sh">python verify.py
</code></pre>
<p>The fixture starts an ephemeral loopback server and supplies a dummy key. On 18 November 2026, four checks passed with Python 3.11: a successful request and an absent-model stop for each of the Haystack and LiteLLM clients. For successful chat it checks the request path, bearer authentication, selected model and 64-token output limit. For an absent model it checks that no chat request follows discovery. It also asserts that the dummy key is absent from captured program output.</p>
<p>These four checks do not exercise HTTP error retries, streaming, tools or a live model. Although the code configures retries to zero, this fixture does not inject a failing HTTP response to test that setting.</p>
<p>A 64-token output cap is not a total spending cap. Input and other billable usage depend on the model. A timeout also does not prove that a server performed no work; check usage before repeating a request.</p>
<p>For the service's endpoint configuration and request-ID guidance, see the <a href="https://cheapclankers.com/docs">CheapClankers API docs</a>. Start with this small request, inspect what happened, then test the features your application needs.</p>
]]></content:encoded></item><item><title><![CDATA[Debug a Python AI API integration in three layers: access, protocol, availability]]></title><description><![CDATA[Check model access, chat protocol support and availability with the OpenAI Python SDK, a custom base URL and explicit retry settings.]]></description><link>https://cheapclankers.hashnode.dev/debug-a-python-ai-api-integration-in-three-layers-access-protocol-availability</link><guid isPermaLink="true">https://cheapclankers.hashnode.dev/debug-a-python-ai-api-integration-in-three-layers-access-protocol-availability</guid><category><![CDATA[Python]]></category><category><![CDATA[api]]></category><dc:creator><![CDATA[CheapClankers]]></dc:creator><pubDate>Wed, 18 Nov 2026 19:08:25 GMT</pubDate><content:encoded><![CDATA[<p>Disclosure: this tutorial is published by CheapClankers, an independent developer API service. The endpoint below is ours. API usage credit is separate from consumer AI subscriptions, and provider names do not imply endorsement. Prepared with AI; the companion examples were verified against a local mock API, not production inference.</p>
<p>Suppose your Python client authenticates successfully and returns a model list, but a completion still fails. Those two results are compatible. Model access, protocol support and current availability answer different questions.</p>
<h2>1. Establish what the key can access</h2>
<p>Use Python 3.9 or later and create a project environment. In Bash or zsh:</p>
<pre><code class="language-sh">python -m venv .venv
source .venv/bin/activate
python -m pip install openai==2.24.0
export CLANKER_API_KEY="your_key_here"
export CLANKER_MODEL="your_enabled_chat_model_id"
</code></pre>
<p>On Windows PowerShell, activate with <code>.\.venv\Scripts\Activate.ps1</code>, and set variables with <code>$env:CLANKER_API_KEY = "your_key_here"</code> and <code>$env:CLANKER_MODEL = "your_enabled_chat_model_id"</code>.</p>
<p>Select an exact ID from the current catalogue and ensure the key permits it. Save the following as <code>check.py</code>:</p>
<pre><code class="language-python">import os
from openai import OpenAI

model = os.environ["CLANKER_MODEL"]
with OpenAI(
    api_key=os.environ["CLANKER_API_KEY"],
    base_url="https://api.cheapclankers.com/v1",
    max_retries=0,
    timeout=30.0,
) as client:
    models = client.models.list()
    ids = [item.id for item in models.data]
    print("Accessible IDs:", ids)
    if model not in ids:
        raise SystemExit("Selected model is absent. Check ID and key access.")

    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": "Say hello in one sentence."}],
        max_tokens=128,
    )
    print(response.choices[0].message.content)
</code></pre>
<p>Run <code>python check.py</code> in that shell. Expect the ID list, then a short greeting when the selected chat model is available and the wallet has sufficient credit. The greeting request is metered. A <code>KeyError</code> for either environment name means Python did not receive the variable; it is not an authentication response from the API.</p>
<p>Do not copy model IDs from old examples. If the selected ID is absent, stop and check spelling, model restrictions and account access. A model visible elsewhere in a catalogue may still be unavailable to this particular key.</p>
<h2>2. Match the protocol to the operation</h2>
<p><code>client.chat.completions.create()</code> sends a chat-completions request. A model listed for a key may instead support Messages or Responses. Confirm that the current catalogue entry lists <strong>chat</strong> before using this example.</p>
<p>The Python constructor uses <code>base_url</code>, with an underscore. The JavaScript SDK uses <code>baseURL</code>. Both take the API root, not a URL ending in <code>/chat/completions</code>.</p>
<h2>3. Check current availability and credit</h2>
<p>A model list is not an uptime probe. If access and protocol match but a request fails, check current model status, wallet credit and the error's request ID. A 401 points to credentials; a 403 can indicate restricted access; a 404 can indicate that the model or protocol is unavailable. These signals help narrow the investigation, but read the returned error rather than assuming every failure has the same cause.</p>
<p>Automatic retries are disabled here so the diagnostic flow stays explicit. After a timeout or server error, review usage before retrying: a client that stopped waiting cannot establish whether upstream work was billed.</p>
<p>The <a href="https://github.com/MacFinn/cheapclankers-examples">companion GitHub examples</a> contain complete scripts and a loopback-only mock test harness for both Python and Node.js.</p>
<p>For a step-by-step client configuration walkthrough, use the <a href="https://cheapclankers.com/guides/openai-python-sdk">OpenAI Python SDK setup guide</a>.</p>
<p>Keep keys out of notebooks shared publicly and out of source control. For service setup and protocol details, use the <a href="https://cheapclankers.com/docs">CheapClankers API documentation</a>, and check the <a href="https://cheapclankers.com/models">live model catalogue</a> before choosing a model. Refer to the <a href="https://github.com/openai/openai-python#readme">official Python SDK documentation</a> when updating the client.</p>
]]></content:encoded></item></channel></rss>