logo
Docs
Libraries

Libraries

Learn how to use Oxygen's OpenAI compatbile API

You can interact with the API through HTTP requests from any language, via OpenAI official Python bindings, OpenAI official Node.js library, or an OpenAI community-maintained library.

To install the official OpenAI Python bindings, run the following command :

pip install openai
simple_streaming.py
from openai import OpenAI
import sys
 
# This is intended for testing purposes only. Never publish code with hardcoded API keys!
client = OpenAI(api_key="oxy-xxxxxxxxxxx",base_url="https://app.oxyapi.uk/v1")
 
stream = client.chat.completions.create(
    model="llama-3.1-8b-instruct",
    messages=[{"role": "user", "content": "Act like a cow.. Named Daniel !"}],
    stream=True, 
)
for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        sys.stdout.write(chunk.choices[0].delta.content)
        sys.stdout.flush() 

To install the official OpenAI Node.js library, run the following command in your Node.js project directory:

npm install openai 
simple_streaming.js
const { OpenAI } = require("openai")
 
// This is intended for testing purposes only. Never publish code with hardcoded API keys!
const client = new OpenAI({
    apiKey: "oxy-xxxxxxxxxx...", 
    baseURL:"https://app.oxyapi.uk/v1"
});
 
async function main() {
    const stream = await client.chat.completions.create({
        model: 'llama-3.1-8b-instruct',
        messages: [{"role": "user", "content": "Act like a cow.. Named Daniel !"}],
        stream: true,
      });
      for await (const chunk of stream) {
        process.stdout.write(chunk.choices[0]?.delta?.content || '');
      }
}
 
main();