Unofficial SDKs

Although we haven't developed our official SDK, our API interface is designed to be fully compatible with OpenAI. This means that you can seamlessly integrate our API into your projects using the OpenAI SDK to make calls to our services.

Here are examples of how to use the OpenAI SDK to call TheB.AI API interface:

Install

pip install openai

Chat

Feel free to input any of our supported models in the 'model' field, including Claude.

Example

import os
import openai

openai.api_base = "https://api.theb.ai/v1"
# openai.api_base = "https://api.baizhi.ai/v1"
openai.api_key = os.getenv("TheB_AI_API_KEY")

completion = openai.ChatCompletion.create(
  model="claude-instant-1",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ],
  stream=False,
  model_params={
    "temperature": 0.8
  }
)

print(completion.choices[0].message)

Our Search model is currently not compatible with the OpenAI SDK. However, you can directly access the API by referring to the API Reference .

Images

Remember to pass the model parameter.

Example

import os
import openai

openai.api_base = "https://api.theb.ai/v1"
# openai.api_base = "https://api.baizhi.ai/v1"
openai.api_key = os.getenv("TheB_AI_API_KEY")

images = openai.Image.create(
  model="dall-e-2",
  prompt="A cute baby sea otter",
  model_params={
    "n": 1,
    "size": "1024x1024"
  }
)
print(images.data)