POST
/
functions
/
{function_id}
/
call
from opperai import Opper
import time

opper = Opper(http_bearer="YOUR_API_KEY")

# First, create a function to call
unique_name = f"geography_expert_{int(time.time())}"
created_function = opper.functions.create(
    name=unique_name,
    description="Expert in world geography and capital cities",
    instructions="You are a geography expert. Answer questions about countries, capitals, and geography clearly and accurately.",
    model="openai/gpt-4o-mini",
)

print(f"Created function with ID: {created_function.id}")

# Call the function with input data
response = opper.functions.call(
    function_id=created_function.id,
    input={
        "question": "What is the capital of France?",
        "context": "We are discussing European geography.",
    },
    tags={"user": "demo_user", "session": "session_123"},
)

print(f"Span ID: {response.span_id}")
if response.message:
    print(f"Message: {response.message}")
if response.json_payload:
    print(f"JSON Response: {response.json_payload}")
print(f"Cached: {response.cached}")
{
  "span_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "message": "<string>",
  "json_payload": "<any>",
  "audio": {},
  "cached": false
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

function_id
string
required

The id of the function to call

Body

application/json

Response

200
application/json

Successful Response

The response is of type object.