Quick answer
How do I call LLMwithCrypto from Python?
Install the official package with pip install openai, then create the client with base_url="https://llmwithcrypto.com/api/v1" and your key from LLMWITHCRYPTO_API_KEY. LLMwithCrypto answers client.chat.completions.create() like the OpenAI API, for 12 open-weight models such as deepseek-v4-pro or gpt-oss-120b. Streaming, async and tool calls work as usual, as documented on 23 October 2026.
What you need
| Python | 3.9 or newer |
|---|---|
| Package | openai (official); requests for the credits call |
| Base URL | https://llmwithcrypto.com/api/v1 |
| Key | In the environment variable LLMWITHCRYPTO_API_KEY, never in the code |
| Model ids | On the models page or from client.models.list() |
How do I send one request?
Create the client once and reuse it: it keeps the connection open between calls. The SDK reads no environment variable for the base URL on its own here, so pass it explicitly.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://llmwithcrypto.com/api/v1",
api_key=os.environ["LLMWITHCRYPTO_API_KEY"],
)
resp = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[
{"role": "system", "content": "Answer in two sentences."},
{"role": "user", "content": "What is a context window?"},
],
max_tokens=200,
)
print(resp.choices[0].message.content)
print(resp.usage.prompt_tokens, "in,", resp.usage.completion_tokens, "out")
How do I run many requests at once?
Use AsyncOpenAI with asyncio.gather, and a semaphore to cap how many requests run in parallel. Four is a safe start; raise it while you stay under your rate limit. Every account has a per-minute request and token limit, shown in the dashboard; ask support and it can be raised.
import asyncio
import os
from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://llmwithcrypto.com/api/v1",
api_key=os.environ["LLMWITHCRYPTO_API_KEY"],
)
LIMIT = asyncio.Semaphore(4)
async def summarize(text):
async with LIMIT:
resp = await client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[
{"role": "system", "content": "Summarize in one sentence."},
{"role": "user", "content": text},
],
max_tokens=80,
)
return resp.choices[0].message.content
async def main():
docs = ["First report text...", "Second report text...", "Third report text..."]
for summary in await asyncio.gather(*(summarize(d) for d in docs)):
print("-", summary)
asyncio.run(main())
How do I stream the answer?
Pass stream=True and iterate over the chunks; each one carries a piece of text in delta.content. With stream_options={"include_usage": True}, the last chunk carries the token counts. The streaming page explains the format.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://llmwithcrypto.com/api/v1",
api_key=os.environ["LLMWITHCRYPTO_API_KEY"],
)
stream = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Write a haiku about latency."}],
stream=True,
stream_options={"include_usage": True},
max_tokens=120,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print("\n", chunk.usage.prompt_tokens, "in,", chunk.usage.completion_tokens, "out")
How do I know what a request cost?
Multiply the usage counts by the model’s prices per million tokens. As of 23 October 2026, DeepSeek V4 Pro costs $1.254 per million input tokens and $3.762 per million output tokens; the example hard-codes those two numbers, so update them from the pricing page when prices change. The dashboard shows the exact cost of every call.
import os
from openai import OpenAI
# prices per 1M tokens of the models you use, copied from the pricing page
PRICES = {"deepseek-v4-pro": (1.254, 3.762)}
client = OpenAI(
base_url="https://llmwithcrypto.com/api/v1",
api_key=os.environ["LLMWITHCRYPTO_API_KEY"],
)
resp = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "Give me three names for a coffee shop."}],
max_tokens=100,
)
price_in, price_out = PRICES[resp.model]
cost = (resp.usage.prompt_tokens * price_in + resp.usage.completion_tokens * price_out) / 1_000_000
print(resp.choices[0].message.content)
print(f"cost: ${cost:.6f}")
How do I move an existing OpenAI app over?
Three changes, usually in one file:
- The client. Add
base_urland read the key fromLLMWITHCRYPTO_API_KEYwhere you createOpenAI()orAsyncOpenAI(). - The model names. Replace every
gpt-…name with an id from the models page. Search the whole project: model names hide in config files, prompts and tests. - The features you rely on. Chat, streaming and system prompts work everywhere. Tool calling and JSON output depend on the model, so run your existing tests against the model you pick.
Everything else stays: your prompts, your retry logic, your parsing of choices and usage. The switching guide walks through the details.
Where should the key live?
In the environment, never in the code. Locally, a .env file loaded by your app and listed in .gitignore is enough; in production, use the secret store of your host or CI. Give each app or service its own key so that you can revoke one without stopping the others. Make one API key per app, agent or teammate and revoke any of them from the dashboard without touching the others.
Python: common questions
Does the SDK retry on its own?
Yes, the openai package retries some errors twice by default (max_retries). The errors page lists which errors are worth a retry.
Can I keep using my OpenAI code?
Yes. The API speaks the OpenAI chat completions format: point the OpenAI SDK, LangChain or any OpenAI-compatible tool at our base URL with your key, and change the model name. The switching guide lists what to check.
Which Python frameworks work?
Anything that accepts an OpenAI-compatible base URL. The LangChain page shows LangChain and LlamaIndex.