Your AI SDK Can Bill the Same Request Twice. Here Are the 5 Guarantees We Built Into Ours
Your AI SDK can bill the same request twice. We built five production guarantees into devupai, our official Python SDK, and measured each one in production, with tests you can rerun yourself.
On this page
Most teams connect to an AI API the same way: install the OpenAI library, change the base URL, ship. DEVUP AI supports exactly that, and always will. But a connection isn't a contract. Once an AI feature is in production and every request is billed, five questions decide whether you can trust the system and your bill.
What did this request cost? What did the gateway change in it? If the network fails, will my code pay twice? When a long job finishes, is the result really from you, and will I process it once? Is the package I installed the one you built?
We built devupai, the official Python SDK for DEVUP AI, to answer all five in code. This article shows each guarantee with real output from production and measurements you can reproduce on your own machine.

Why build a native SDK when compatibility already works?
The OpenAI library is excellent at what it was designed for: OpenAI's API. Its response types describe OpenAI's fields, and its retry rules are tuned for a general-purpose client.
A DEVUP AI response carries more than that. Every response has a request id. Non-streamed responses carry a _devup block with the cost of the request and your remaining balance. Every response, streamed or not, carries an X-DEVUP-Warnings header when the gateway adapted something. The OpenAI library receives all of it and understands none of it.
So we kept compatibility as the floor, and built the SDK as the ceiling: one client that speaks the whole API, with types for everything DEVUP AI returns.
Guarantee 1: you know what every request cost
Here is the same request, sent on 22 November 2026 through both libraries.
Through the OpenAI library, the billing data is there, but only as an untyped dictionary hidden in the model's extra fields:
type(response): ChatCompletion
hasattr(response, 'devup'): False
response.model_extra keys: ['_devup']
type(model_extra['_devup']): dictThrough devupai, it's a typed field with its own model, DevUpBilling:
from devupai import DevupAI
client = DevupAI() # reads DEVUP_API_KEY
completion = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
messages=[{"role": "user", "content": "In one sentence: what is a reranker?"}],
max_tokens=48,
)
print(completion.devup)cost_dzd=0.0098 balance_dzd=728.75 request_id='req_de6b209205a344ebba841dd463b67c17' warnings=None note=Nonecost_dzd is typed float | None, so your editor completes it and your type checker checks it. That turns cost into data you can build on. A SaaS can meter each of its own customers in dinars, with no estimate and no separate billing export:
from collections import defaultdict
from devupai import DevupAI
client = DevupAI()
spend_by_customer: defaultdict[str, float] = defaultdict(float) # in production, store money as Decimal or in your database
def answer(customer_id: str, question: str) -> str:
completion = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
messages=[{"role": "user", "content": question}],
)
if completion.devup is not None and completion.devup.cost_dzd is not None:
spend_by_customer[customer_id] += completion.devup.cost_dzd
message = completion.choices[0].message
return message.content if message else ""devup.balance_dzd comes back with the same response, so a batch job can stop itself before the balance runs low, without polling a separate endpoint. The devup block comes with non-streamed responses. Streamed responses report their token usage in the final chunk.
Guarantee 2: you know what the gateway changed in your request
DEVUP AI serves more than 200 models from many model makers, and they don't all accept the same parameters. Some reasoning models, for example, take no temperature or top_p.
Rejecting those requests would break every OpenAI-compatible tool that sends default sampling values. DEVUP AI answers them instead, and tells you exactly what it did not apply, as a notice. Notice codes are stable, sorted, and never echo your prompt or your values. The error reference documents every code, from parameter_not_supported to structured_output_not_matched and max_tokens_capped_by_budget.
devupai exposes those codes directly. Sent on 22 November 2026 to openai/gpt-5.4-nano with temperature=0.2:
result = client.chat.completions.with_response.create(
model="openai/gpt-5.4-nano",
messages=[{"role": "user", "content": "Reply with the word OK."}],
temperature=0.2,
max_completion_tokens=200,
)
print(result.warnings) # codes from the X-DEVUP-Warnings header
print(result.data.devup.warnings)['parameter_not_supported']
["This model does not take the 'temperature' parameter; the request was answered without it."]Streams expose the same codes before the first chunk arrives, so your code can decide before it renders a single token:
before the first chunk -> request_id: req_8d72f696679a4fbcb0f878c8a2cc8939 | warnings: ['parameter_not_supported']Because the codes are stable, you can turn them into a test. This one fails your CI the day a prompt or a model change makes the gateway drop a parameter, or return JSON that doesn't match your schema:
from devupai import DevupAI
client = DevupAI()
FORBIDDEN = {"parameter_not_supported", "structured_output_not_matched"}
def test_invoice_extraction_is_applied_as_written() -> None:
result = client.chat.completions.with_response.create(
model="openai/gpt-5.4-nano",
messages=[{"role": "user", "content": "Extract the invoice total: 1,250 DZD."}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "invoice_total",
"schema": {
"type": "object",
"properties": {"total_dzd": {"type": "number"}},
"required": ["total_dzd"],
"additionalProperties": False,
},
},
},
max_completion_tokens=200,
)
assert not FORBIDDEN & set(result.warnings), result.warningsA silent adaptation stays invisible until it breaks something. DEVUP AI tells you, and the SDK makes it testable.
Guarantee 3: a billed request is never resent blind
This is the guarantee most teams only think about after it costs them.
Picture a long answer. Your client waits 60 seconds and gives up, but the model was still writing. On an API that bills every completed request, that work may already be paid for. Now your SDK resends the same request on its own. You can pay twice for one answer, and your logs show a single call.
We measured how often SDKs resend the same request. A local mock server answers one chat completion with one failure at a time, and counts how many times the request arrives. Both libraries ran with their default settings and a 1-second timeout (22 November 2026, Python 3.13):
| SDK | 500 | 502 | 503 | 504 | 429 | read timeout | connection dropped after send |
|---|---|---|---|---|---|---|---|
openai 3.57.0 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
devupai 1.0.1 | 1 | 1 | 3 | 1 | 3 | 1 | 1 |

A general-purpose client retries broadly, and for many APIs that's a sensible default. devupai is the SDK of a billing platform, so it follows one rule: a billed request is sent again only when it is known not to have run.
A
429or a503usually means the request was refused before any work. The SDK waits for the time inretry-after-msorRetry-After, then tries again.A connection that never opened never reached us, so it's retried too.
When the platform cannot promise that a request did not run, it says so with
x-should-retry: false, and the SDK sends nothing again, whatever the status. On the same mock server, a503carrying that header arrives once instead of three times.Every other failure (a read timeout, a dropped connection, a
500,502or504) is returned to your code with its request id. You decide what happens next.
The test is open source: sdk-retry-test runs on localhost, needs no API key, and measures any SDK you add to it.
The platform protects you too
The SDK is one layer. The platform is the other. We measured it in production on 22 November 2026, with the same long request sent twice:
CONTROL client waits for the answer answered in 29.2 s balance change: 0.51 DZD
ABORT client gives up after 3 s APITimeoutError balance change: 0.0 DZDWhen your code stops waiting before the answer is complete, DEVUP AI cancels the request and charges nothing. When a model fails on its side, you get a 502 and pay nothing. When you stop a stream, you pay for the input and the output already sent, never more.
Two layers, each enough on its own. That's what defense in depth means for a bill.
When you do want to retry by hand, devupai makes it explicit:
from devupai import APITimeoutError, DevupAI
client = DevupAI(max_retries=0) # nothing is ever resent for you
try:
completion = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
messages=[{"role": "user", "content": "Summarize this contract."}],
timeout=60,
)
except APITimeoutError:
# Your decision: retry, queue for later, or tell the user.
raiseAn on_debug hook reports every retry the SDK makes, with the attempt number, the status and the wait.
Guarantee 4: long jobs come back signed, and you process them once
Some jobs take minutes: a long generation, a batch of documents, a video. Holding an HTTP connection open for that is fragile.
DEVUP AI's Native API accepts a webhook URL instead. The API answers at once with queued, and sends the result to your endpoint when it is ready. Webhooks are a feature of the Native API, so the OpenAI library has no method for them.
from devupai import DevupAI
client = DevupAI()
job = client.inference.run(
"deepseek-ai/DeepSeek-V4-Pro",
{
"input": "Draft a 2,000-word technical report on solar farms in the Sahara.",
"parameters": {"max_new_tokens": 3000},
"webhook": "https://your-app.com/devupai-webhook",
},
)
print(job)Every delivery is signed with HMAC-SHA256 over the raw body and a timestamp, in the X-DevUp-Signature header. devupai verifies it for you, locally, without sending anything:
import os
from collections.abc import Mapping
from devupai import DevupWebhookVerificationError, construct_webhook_event
from devupai.types import WebhookErrorPayload
SECRET = os.environ["DEVUP_WEBHOOK_SECRET"]
processed: set[str] = set() # use your database in production
def handle_delivery(raw_body: bytes, headers: Mapping[str, str]) -> int:
h = {name.lower(): value for name, value in headers.items()}
try: # verify first: unsigned requests learn nothing
event = construct_webhook_event(
raw_body=raw_body,
signature_header=h.get("x-devup-signature", ""),
secret=SECRET,
)
except DevupWebhookVerificationError as err:
print("rejected:", err.reason)
return 400
delivery_id = h.get("x-devup-delivery-id", "")
if delivery_id and delivery_id in processed:
return 200 # a verified retry of a delivery we already handled
if isinstance(event, WebhookErrorPayload):
print("job failed:", event.error.type)
else:
print("result:", event.results, "| cost:", event.cost_dzd, "DZD")
if delivery_id:
processed.add(delivery_id)
return 200We ran the verifier against four deliveries:
| Delivery | Result |
|---|---|
| Correctly signed | accepted, typed WebhookSuccessPayload with cost_dzd |
| Body changed by one character | rejected: no_matching_signature |
| A valid delivery replayed one hour later | rejected: timestamp_outside_tolerance |
| During a secret rotation: one old and one new signature | accepted |
That last case matters. You can rotate your webhook secret without downtime, because both secrets are valid during the rotation window.
Deduplicate on X-DevUp-Delivery-Id, never on the signature. The delivery id stays the same across retries, while the signature is recomputed on every attempt. If your endpoint is down, DEVUP AI keeps trying, with up to 8 delivery attempts over about two hours (webhooks docs).
The endpoints compatibility can't reach
Webhooks aren't the only part of the API the OpenAI library can't call. devupai covers the whole platform from one client: chat, the Responses API, images, embeddings, reranking, speech, transcription, video, native inference, models, balance and service health.
Reranking is a good example. It's the step that makes retrieval-augmented generation (RAG) accurate: after a fast vector search returns 50 candidate passages, a reranker reads each one against the question and keeps the best few. With devupai, it's one call, with the cost on the response like everything else:
passages = [
"Top up your DEVUP AI balance in dinars with BaridiMob, CIB or Edahabia.",
"Algiers is the capital of Algeria.",
"Prepaid balance top-ups accept Algerian payment cards.",
]
ranked = client.rerank.create(
model="Qwen/Qwen3-Reranker-4B",
query="How do I pay for API usage from Algeria?",
documents=passages,
top_n=3,
)
for r in ranked.results:
print(f"{r.relevance_score:.4f} {passages[r.index]}")
print("cost:", ranked.devup.cost_dzd if ranked.devup else None, "DZD")Real output, 22 November 2026. Both passages about payment rank first, and the true but irrelevant sentence about Algiers is pushed to the bottom:
0.9975 Top up your DEVUP AI balance in dinars with BaridiMob, CIB or Edahabia.
0.9962 Prepaid balance top-ups accept Algerian payment cards.
0.0361 Algiers is the capital of Algeria.
cost: 0.0025 DZDGuarantee 5: the package you installed is the one we built
Supply-chain attacks target packages, not just servers. A typo in a package name or a stolen publishing token can put someone else's code inside your application.
devupai is published through PyPI Trusted Publishing: the upload uses a short-lived credential issued to the release workflow, not a stored password or token. Each release is built by a GitHub Actions workflow in the public repository, and PyPI stores a signed attestation for every file (PEP 740). The attestation ties the exact file to:
the repository
devupai-platform/devupai-python;the workflow
release.yml;the protected
pypienvironment.
You can check it yourself, in one command:
pip install pypi-attestations
python -m pypi_attestations verify pypi \
--repository https://github.com/devupai-platform/devupai-python \
pypi:devupai-1.0.1-py3-none-any.whlOK: devupai-1.0.1-py3-none-any.whlThe check also fails when it should. Point it at any other repository and it refuses:
Verification failed: provenance was signed by repository "devupai-platform/devupai-python", expected "someone-else/fake"The package itself stays small and auditable. It depends only on httpx and pydantic, ships its type information (py.typed), and is MIT-licensed, with a public changelog.
Provenance continues at runtime. Every response, stream and error carries the request id DEVUP AI assigned (x-request-id). If you send your own x-client-request-id, it comes back too, so one id follows a request from your logs to our support.

When to keep the OpenAI library
Use whichever fits the code you own.
Frameworks that expect an OpenAI client, such as LangChain, CrewAI or the OpenAI Agents SDK, connect through DEVUP AI's OpenAI-compatible endpoint. They keep working, and the integration guides show how.
Code you write and run yourself, such as a backend, a worker or a data pipeline, gets the five guarantees with
devupai.
Both bill the same dinar balance, and you can mix them in one project.
Migrate in two lines
- from openai import OpenAI
- client = OpenAI(api_key=os.environ["DEVUP_API_KEY"], base_url="https://api.devupai.com/v1")
+ from devupai import DevupAI
+ client = DevupAI() # reads DEVUP_API_KEYclient.chat.completions.create(...) keeps the same name and the same request fields. What changes is what comes back: typed cost, notices, request ids, and safe retries. The Python SDK guide covers streaming, async, file inputs, timeouts and every error type.
Frequently asked questions
Is devupai a fork of the OpenAI library?
No. It's an independent SDK built from DEVUP AI's OpenAPI specification, with its own retry policy and its own types for everything the API returns. Request fields keep the familiar names, so moving code over is quick.
Which Python versions does it support?
Python 3.11 or later. It ships both a synchronous client, DevupAI, and an asynchronous one, AsyncDevupAI, with the same methods and options.
How do I see what a request cost in dinars?
Read completion.devup.cost_dzd on any non-streamed response. The same block gives balance_dzd and request_id. For streams, token usage arrives in the final chunk.
Can an SDK charge me twice for the same request?
On a pay-per-request API, yes: a client that resends a request after a timeout can pay for work that was already done. devupai never resends a billed request unless it is known not to have run. On top of that, DEVUP AI doesn't charge a request you abandon before the answer is complete.
Does it support streaming and async?
Yes. Streams are typed. They expose the request id and notice codes before the first chunk, and report token usage at the end. Every method is also available on AsyncDevupAI with await.
How do I verify the package is authentic?
Run pypi-attestations verify pypi against the devupai-platform/devupai-python repository, as shown above. It checks the signed provenance PyPI stores for each release file.
Can I keep using the OpenAI library with DEVUP AI?
Yes. The OpenAI-compatible endpoint at https://api.devupai.com/v1 stays fully supported. Use devupai where you want the five guarantees, and the OpenAI library where a framework expects it.
Quick summary for Python teams
devupai is the official Python SDK for DEVUP AI, for Python 3.11 and later, with synchronous and asynchronous clients. It gives you five production guarantees:
Each request's cost in dinars, as a typed field.
The gateway's notices as stable codes you can test in CI.
No blind resend of a billed request, measured side by side with the OpenAI library.
Signed webhooks with replay protection and secret rotation.
Release files with signed build provenance you can verify in one command.
The platform adds its own layer: a request you abandon before the answer is complete is not charged. Install it with pip install devupai. The source is on GitHub, the package on PyPI, and the full guide in the docs.
For a vendor-neutral way to audit any AI API, read our guide to AI APIs and cloud GPUs in Algeria.
Create your DEVUP AI account and run pip install devupai today.
About DEVUP AI
AI infrastructure for developers — models, compute and media APIs with local DZD billing via BaridiMob and Edahabia.
Get an API key