npm install openai
pip install openai
composer require openai-php/client
const OpenAI = require('openai');
const client = new OpenAI({
apiKey: process.env.CORE_API_KEY,
baseURL: 'https://api.coreapi.com/v1'
});
async function chatExample() {
try {
const response = await client.chat.completions.create({
model: 'gpt-4-turbo',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello, how are you?' }
],
temperature: 0.7,
max_tokens: 150
});
console.log(response.choices[0].message.content);
} catch (error) {
console.error('Error:', error);
}
}
chatExample();async function generateImage() {
try {
const response = await client.images.generate({
model: 'dall-e-3',
prompt: 'A serene mountain landscape at sunrise',
size: '1024x1024',
quality: 'standard',
style: 'natural',
n: 1
});
console.log('Generated image URL:', response.data[0].url);
} catch (error) {
console.error('Error:', error);
}
}from openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv('CORE_API_KEY'),
base_url='https://api.coreapi.com/v1'
)
def chat_example():
try:
response = client.chat.completions.create(
model='gpt-4-turbo',
messages=[
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'Hello, how are you?'}
],
temperature=0.7,
max_tokens=150
)
print(response.choices[0].message.content)
except Exception as e:
print(f'Error: {e}')
chat_example()def streaming_chat():
try:
stream = client.chat.completions.create(
model='gpt-4-turbo',
messages=[
{'role': 'user', 'content': 'Tell me a short story'}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end='')
except Exception as e:
print(f'Error: {e}')
streaming_chat()https://api.coreapi.com/v1Authorization: Bearer YOUR_API_KEYapplication/jsonMori API is an AI model aggregation platform that gives developers a single, unified API to access 50+ AI models across text, image, audio, and video — with transparent pricing, real‑time analytics, and enterprise‑grade reliability.