Replacing your OpenAI API calls with ZC Inference Exchange's OpenAI-compatible API is straightforward and can significantly reduce your costs. By simply updating the API endpoint URL, you can achieve the same functionality at a fraction of the cost. This guide will show you how to make the switch with a concrete example, demonstrating the before and after code changes, and the resulting cost savings.
To illustrate the process, let's start with a typical integration of the OpenAI API into an application. The following is a simplified example of how an application might call the /v1/chat/completions endpoint:
import requests
headers = {
'Authorization': 'Bearer YOUR_OPENAI_API_KEY'
}
data = {
'model': 'qwen2.5:32b',
'messages': [{'role': 'user', 'content': 'What is the capital of France?'}]
}
response = requests.post('https://api.openai.com/v1/chat/completions', headers=headers, json=data)
print(response.json())
To switch to ZC Inference Exchange, you'll need to update the endpoint URL and ensure you have a valid Bearer token for authentication. Here's how the same code would look with ZC Inference Exchange:
import requests
headers = {
'Authorization': 'Bearer YOUR_ZC_INFERENCE_EXCHANGE_API_KEY'
}
data = {
'model': 'qwen2.5:32b',
'messages': [{'role': 'user', 'content': 'What is the capital of France?'}]
}
response = requests.post('https://zcx.zctechnologies.org/v1/chat', headers=headers, json=data)
print(response.json())
The cost savings are substantial. For instance, the Starter plan at ZC Inference Exchange offers 1.5M tokens for $99 per month, which is equivalent to $66 per 1M tokens. In contrast, OpenAI's pricing is significantly higher, making ZC Inference Exchange a cost-effective solution for your LLM needs.
Switching to ZC Inference Exchange for your LLM needs is a simple and effective way to reduce costs without compromising on functionality. By changing just one URL and obtaining a Bearer token, you can start saving up to 70% on your LLM costs. To get started, sign up for a prepaid LLM credit line at https://zcx.zctechnologies.org#plans.