How to reduce LLM API costs
Practical ways to cut your AI API bill without hurting quality.
Ten practical levers
- Route simple requests to a small model.
- Cap reply length with max_tokens.
- Shorten and reuse system prompts; cache them where supported.
- Trim old conversation turns.
- Use low thinking levels for routine tasks.
- Batch classification into fewer, larger prompts.
- Store results you will reuse instead of regenerating them.
- Embed documents once and store the vectors.
- Pick image and video resolutions you actually need.
- Watch the usage field in every response.
Example
from openai import OpenAI
client = OpenAI(api_key="YOUR_TOKENREX_KEY", base_url="https://tokenrex.ai/api/public")
resp = client.chat.completions.create(
model="gpt-6-luna",
messages=[{"role": "user", "content": "Summarise in 2 lines"}],
max_tokens=120,
)
print(resp.choices[0].message.content)Questions
- Do I need a separate key for each provider?
- No. One TokenRex API key works for every enabled model; change only the model ID.
Related
- What is prompt caching?
- How much does an AI chatbot cost per month?
- How to use the OpenAI SDK with a custom base URL
- How to call Claude with the OpenAI SDK
- How to call Gemini with the OpenAI SDK
- How to use the Anthropic Messages API on TokenRex
- How to stream LLM responses
- How to use function calling (tools) with an LLM API
- How to send images to a vision model
- How to generate images with an API