1. Create an API key

Log in at platform.opper.ai and create your own API key in the top right menu. Each api key is associated with a project, you will have all calls, functions, indexes and traces associated with this project. There is a default project for each organization but it is recommended to create a new project to better being able to separate the different applications and environments.

2. Set the API key

Set the API key as the OPPER_API_KEY environment variable.

export OPPER_API_KEY="your-api-key"

3. Install the Opper SDK

Install our SDK for your preferred language. There are currently SDKs available for Python and TypeScript. If your language is not supported, you can use the REST API directly. See the API reference for more information.

pip install opperai

4. Complete your first task

Let’s write a simple call that extracts room descriptions from text as structured output.

from opperai import Opper
# Our SDK supports Pydantic to provide structured output
from pydantic import BaseModel
import os

# Define the output structure
class RoomDescription(BaseModel):
    room_count: int
    view: str
    bed_size: str
    hotel_name: str

def main():
    opper = Opper(http_bearer=os.getenv("OPPER_API_KEY"))

    # Complete a task
    completion = opper.call(
        name="extractRoom",
        instructions="Extract details about the room from the provided text",
        input="The Grand Hotel offers a luxurious suite with 3 spacious rooms, each providing a breathtaking view of the ocean. The suite includes a king-sized bed, an en-suite bathroom, and a private balcony for an unforgettable stay.",
        output_schema=RoomDescription,
    )

    print(completion.json_payload)
    #{'room_count': 3, 'view': 'ocean', 'bed_size': 'king-sized', 'hotel_name': 'The Grand Hotel'}

main()

4. View task input and outputs in the platform

Check out your call in the traces page.