OpenAI Compatible API

If you’ve been using OpenAI API such as GPT-4 and GPT-4 Turbo, switching to Hyperbolic API is easy!

On the Models page, each model contains code examples in curl, Python, TypeScript, and Gradio. Below are a few examples on integrating with your existing codebase.

Text

Install OpenAI's Python/TypeScript SDK:

python3 -m pip install openai
npm install openai

Simply replace the api_key and base_url to the Hyperbolic ones in your project.

import os
import openai

system_content = "You are a gourmet chef. Be descriptive and helpful."
user_content = "Tell me about Chinese hotpot"

client = openai.OpenAI(
    api_key=HYPERBOLIC_API_KEY,
    base_url="https://api.hyperbolic.xyz/v1",
    )

chat_completion = client.chat.completions.create(
    model="meta-llama/Meta-Llama-3-70B-Instruct",
    messages=[
        {"role": "system", "content": system_content},
        {"role": "user", "content": user_content},
    ],
    temperature=0.7,
    max_tokens=1024,
)

response = chat_completion.choices[0].message.content
print("Response:\n", response)
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: HYPERBOLIC_API_KEY,
  baseURL: 'https://api.hyperbolic.xyz/v1',
});

async function main() {
  const response = await client.chat.completions.create({
    messages: [
      {
        role: 'system',
        content: 'You are an expert travel guide.',
      },
      {
        role: 'user',
        content: 'Tell me fun things to do in San Francisco.',
      },
    ],
    model: 'meta-llama/Meta-Llama-3-70B-Instruct',
  });

  const output = response.choices[0].message.content;
  console.log(output);
}

main();