API & Libraries
REST API

REST API

The API Reference for the two HyperChat™ APIs can be found in the links below:

Chat Completion

The Chat Completion API answers user queries directly, without reference to Collections, only using chat history and the internal knowledge of the LLM. The following provides examples to use this API with cURL as well as over Python with the requests package. Note that the Python example here is not the Python client. See the Python page (opens in a new tab) for more information on our Python Client and how to programmatically integrate our API into your application.

cURL example

The following is an example code for chat completion requests with curl. Note that you need to define the $HYPERBEE_API_KEY environment variable to contain your actual API key.

curl -X 'POST' \
  'https://api.hyperbee.ai/v1/chat/completions' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $HYPERBEE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "hyperchat",
  "optimization": "premium",
  "messages":[
        {"role": "system", "content": "You are an AI assistant designed to help the user."},
        {"role": "user", "content": "Hello, I want to learn more about how satellites work."}
    ]
}'

The following customizations are possible on the API parameters:

  • You can override the default system prompt by providing one as the first element of your messages array
  • Just like in the Chat (opens in a new tab) web interface, you can choose an HyperChat™ optimization scheme (fast, auto, or premium) based on your cost, speed and accuracy requirements. Visit the Chat (opens in a new tab) page and hover over the optimizations choices for more information.
  • Other than these HyperChat™-specific parameters, default generation parameters like max_tokens, temperature and stream are also available as part of the API template. See the API ReDoc (opens in a new tab) for more information.

Python example

The following is an example code for chat completion request with requests library.

import requests
import os
 
url = "https://api.hyperbee.ai/v1/chat/completions"
 
payload = {
    "model": "hyperchat",
    "optimizations": "premium",
    "messages":[
        {"role": "system", "content": "You are an AI assistant designed to help the user."},
        {"role": "user", "content": "Hello, I want to learn more about how satellites work."}
    ],
    "max_tokens": 256
}
headers = {
    'accept': 'application',
    'Authorization': f'Bearer {os.environ["HYPERBEE_API_KEY"]}', 
    # Replace with your actual API key with HYPERBEE_API_KEY or set it as environment variable
    'Content-Type': 'application/json'
}
 
response = requests.request("POST", url, headers=headers, json=payload)
 
print(response.text)

Example output:

{
  "id":"cmpl-12345678910111213141516171819202",
  "object":"chat.completion",
  "created":1234567891,
  "model":"hyperchat",
  "choices":
  [
    {
      "index":0,
      "message":
      {
        "role":"assistant",
        "content":"Sure! Satellites are fascinating devices that orbit Earth or other celestial bodies and serve various purposes, including communication, weather monitoring, navigation, and scientific research. Here’s a basic overview of how satellites work:\n\n### 1. **Basic Components of a Satellite**\n   - **Payload**: This is the main functional part of the satellite, which includes the instruments or equipment designed for specific tasks, such as cameras, sensors, or communication devices.\n   - **Bus**: This is the support structure that houses the payload and includes systems for power, thermal control, communication, and attitude control.\n   - **Power System**: Most satellites use solar panels to generate electricity, which powers all onboard systems. Batteries are often included to store energy for use when the satellite is in the Earth's shadow.\n   - **Communication System**: This system allows the satellite to communicate with ground stations and other satellites, sending and receiving data.\n   - **Attitude Control System**: This system helps to orient the satellite in the correct direction using reaction wheels, thrusters, or magnetorquers.\n\n### 2. **Orbits**\n   - Satellites can be placed in various types of orbits, depending on their mission:\n     - **Low Earth Orbit (LEO)**:",
        "tool_calls":null
     },
     "logprobs":null,
     "finish_reason":"length",
     "stop_reason":null
   }
 ],
   "usage":
   {
     "prompt_tokens":34,
     "total_tokens":290,
     "completion_tokens":256
   }
}
 

Note that since the max_tokens parameter set to 256, the response is truncated. As shown in the finish reason. To get the full response, you can set the max_tokens parameter to a higher value.

RAG API: Chat Completion

The RAG API is similar to the Chat Completion API, but it answers user queries with respect to data residing in Collections. The only difference in the RAG API template is the namespace parameter which takes in the Collection UUID.

cURL example

curl -X 'POST' \
  'https://api-rag.hyperbee.ai/v1/chat/completions' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $HYPERBEE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "hyperchat",
  "optimization": "premium",
  "namespace": "<COLLECTION_NAMESPACE_ID>",
  "messages":[
        {"role": "system", "content": "You are an AI assistant designed to help the user."},
        {"role": "user", "content": "Hello, I want to learn more about how satellites work."}
    ]
}'

Python example

import requests
import os
 
url = "https://api-rag.hyperbee.ai/v1/chat/completions"
 
payload = {
    "model": "hyperchat",
    "optimizations": "premium",
    "namespace": "<COLLECTION_NAMESPACE_ID>",
    "messages":[
        {"role": "system", "content": "You are an AI assistant designed to help the user."},
        {"role": "user", "content": "Hello, I want to learn more about how satellites work."}
    ],
    "max_tokens": 256
}
headers = {
    'accept': 'application',
    'Authorization': f'Bearer {os.environ["HYPERBEE_API_KEY"]}', 
    # Replace with your actual API key with HYPERBEE_API_KEY or set it as environment variable
    'Content-Type': 'application/json'
}
 
response = requests.request("POST", url, headers=headers, json=payload)
 
print(response.text)