Skip to main content

Basic Usages

This section will cover the most basic usage of using TaskingAI's OpenAI-compatible API to perform chat completion tasks using OpenAI SDK.

Initialize the OpenAI client

To use the OpenAI-compatible API through OpenAI SDK, you need to initialize the OpenAI client with your TaskingAI API key and the base URL set to https://oapi.tasking.ai.

from openai import OpenAI

client = OpenAI(
api_key="YOUR_TASKINGAI_API_KEY",
base_url="https://oapi.tasking.ai/v1",
)

Specify the model or assistant of your choice

On TaskingAI, you can configure multiple chat completion models from dozens of providers. You can also further create your own assistant by combining models, retrievals, and plugins.

With TaskingAI's OpenAI-compatible API, you can interact with any of these models or assistants. All you need to do is to provide the id of your target model or assistant to the model parameter in the request body.

response = client.chat.completions.create(
model="YOUR_TASKINGAI_MODEL_ID", # or an assistant ID
messages=[
{"role": "user", "content": "Hello, how are you?"},
]
)

print(response)

For detailed information about the response schema, please refer to OpenAI's chat completion API reference.

note

Note that if you are using an assistant ID, it will be treated as a stateless agent invocation and no chat history will be stored.