Python API

The Hyperbolic API provides compatibility for the OpenAI API standard, allowing easier integrations into existing applications.

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

Requirements

Install OpenAI's Python SDK:

python3 -m pip install openai

Example code

Simply replace the api_key and base_url to the Hyperbolic ones.

import os
import openai

system_content = "You are a gourmet. 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)