GA
Global API
DocsGet Started

JavaScript/TS SDK

JavaScript / TypeScript SDK

Use the official OpenAI JavaScript SDK.

Installation

npm install openai

Full Example

import OpenAI from 'openai';

const client = new OpenAI({

apiKey: process.env.GLOBAL_API_KEY,

baseURL: 'https://global-apis.com/v1',

});

// Chat

const chat = await client.chat.completions.create({

model: 'deepseek-chat',

messages: [

{ role: 'system', content: 'You are a helpful assistant.' },

{ role: 'user', content: 'What is TypeScript?' },

],

temperature: 0.7,

max_tokens: 500,

});

console.log(chat.choices[0].message.content);

// Streaming

const stream = await client.chat.completions.create({

model: 'deepseek-chat',

messages: [{ role: 'user', content: 'Count to 3' }],

stream: true,

});

for await (const chunk of stream) {

process.stdout.write(chunk.choices[0].delta.content ?? '');

}

Get Started Free →