Pearl APIDocsReference

Quickstart: Your first API request

Pearl API is accessible using the OpenAI libraries (Python and TypeScript / Javascript) along with the REST API, by updating three lines.

To use the OpenAI API in Python, you can use the official OpenAI SDK for Python. Get started by installing the SDK using pip:

pip install openai

With the OpenAI SDK installed, create a file called example.py and copy the following example into it:

from uuid import uuid4
from openai import OpenAI

client = OpenAI(
    api_key="PEARL_API_KEY",
    base_url="https://api.pearl.com/api/v1/"
)

session_id = str(uuid4())  # Generate a unique GUID

response = client.chat.completions.create(
    model="pearl-ai",
    messages=[
        {
            "role": "user",
            "content": "Explain to me how AI works"
        }
    ],
    metadata={"sessionId": session_id}
)

print(response.choices[0].message)

Every request must include a unique sessionId in GUID format as a metadata attribute, which serves as a unique identifier for each conversation session.

Conversation modes