Complete guide to use OpenAI SDK with v98store proxy API
This guide demonstrates how to use the OpenAI SDK with v98store proxy API. You can use the official OpenAI SDK in both TypeScript/JavaScript and Python by simply changing the baseURL to point to v98store.
To use v98store proxy API, you only need to change two things:
https://api.openai.com/v1 to https://v98store.com/v1Important: Replace <YOUR_API_KEY> in the examples below with your actual API key from v98store.
First, install the OpenAI SDK package:
npm install openai
Or if you're using yarn:
yarn add openai
Here's a complete example using TypeScript/JavaScript:
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://v98store.com/v1',
apiKey: '<YOUR_API_KEY>',
});
async function main() {
const completion = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{
role: 'user',
content: 'What is the meaning of life?',
},
],
});
console.log(completion.choices[0].message);
}
main();
Key Points:
baseURL to https://v98store.com/v1apiKey fieldFirst, install the OpenAI Python package:
pip install openai
Or if you're using pip3:
pip3 install openai
Here's a complete example using Python:
from openai import OpenAI
client = OpenAI(
base_url="https://v98store.com/v1",
api_key="<YOUR_API_KEY>",
)
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": "What is the meaning of life?"
}
]
)
print(completion.choices[0].message.content)
Key Points:
base_url to https://v98store.com/v1api_key parameterThe v98store proxy API supports all standard OpenAI API operations:
chat.completions.create()embeddings.create()images.generate()audio.transcriptions.create()audio.translations.create()You can use any model available through v98store. Simply specify the model name in your request:
// TypeScript/JavaScript
model: 'gpt-4o'
model: 'gpt-4-turbo'
model: 'gpt-3.5-turbo'
model: 'claude-3-opus'
// ... and many more
Check the Model Prices page to see all available models.
For better security, store your API key in environment variables:
const openai = new OpenAI({
baseURL: 'https://v98store.com/v1',
apiKey: process.env.V98STORE_API_KEY,
});
import os
from openai import OpenAI
client = OpenAI(
base_url="https://v98store.com/v1",
api_key=os.getenv("V98STORE_API_KEY"),
)
Always include proper error handling in your code:
try {
const completion = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(completion.choices[0].message);
} catch (error) {
console.error('Error:', error);
}
try:
completion = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
print(completion.choices[0].message.content)
except Exception as e:
print(f"Error: {e}")