Learn how to use OpenAI SDKs with Electron Hub as your base URL
Use Electron Hub with the official OpenAI SDKs by simply changing the base URL. This allows you to access 450+ AI models through familiar OpenAI interfaces.
import OpenAI from 'openai';const openai = new OpenAI({ apiKey: 'ek-your-api-key-here', baseURL: 'https://api.electronhub.ai/v1',});// Use any model available on Electron Hubconst completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [ { role: "user", content: "Hello, world!" } ],});console.log(completion.choices[0].message);
const embedding = await openai.embeddings.create({ model: "text-embedding-3-large", input: "The quick brown fox jumps over the lazy dog",});console.log(embedding.data[0].embedding);
stream = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Tell me a story"}], stream=True)for chunk in stream: if chunk.choices[0].delta.content is not None: print(chunk.choices[0].delta.content, end="")