Skip to main content

Reef Python SDK

Server-side Python client for Reef. Product servers authenticate with an InkPass API key or service credential. Provider credentials remain inside Reef.

Install

pip install reef-sdk

Create a typed decision

The decision client accepts choice, score, and noul questions in one request. Use the rolling Jev alias to follow the latest release, or use a pinned model ID when reproducibility matters.

import os

from reef_sdk import DecisionCreateRequest, ReefClient, ReefConfig


request: DecisionCreateRequest = {
    "state": {
        "ticket": "I upgraded to Pro, still see Free, and was charged.",
    },
    "questions": {
        "route": {
            "type": "choice",
            "instructions": "Choose the team that should handle this ticket.",
            "criteria": {
                "billing": "Billing, subscription, or charge issue",
                "technical": "Technical product malfunction",
                "account": "Account access or identity issue",
            },
        },
        "urgency": {
            "type": "score",
            "instructions": "Score the urgency of this ticket.",
            "criteria": ["low", "medium", "high"],
        },
        "billing_related": {
            "type": "noul",
            "instructions": "Does this ticket concern billing?",
        },
    },
    "requested_model": "~typesafe/jev-latest",
    "model_policy_id": "decision_model_default",
}

with ReefClient(
    ReefConfig(
        "https://reef.example.com",
        os.environ["REEF_SERVICE_API_KEY"],
        credential_kind="service",
    )
) as reef:
    decision = reef.decisions.create(
        "support-product",
        request,
        idempotency_key="ticket-4821-routing-v1",
    )

if decision["status"] == "completed":
    route = decision["answers"]["route"]
    if route["type"] == "choice":
        print(route["choice"], route["confidence"])

DecisionResponse is a status-discriminated union. Completed responses require typed answers, provider metadata, and usage. The SDK rejects a malformed successful response instead of passing an untyped dictionary to application code.

Ask for a structured answer

prompts.ask_structured sends one synchronous prompt with a JSON Schema for the answer. Reef validates the model's JSON against the schema before it completes the prompt, and the SDK returns the parsed value as answer.

answer = reef.prompts.ask_structured(
    "support-product",
    "Route this ticket: I upgraded to Pro and was charged twice.",
    response_schema={
        "type": "object",
        "properties": {"team": {"enum": ["billing", "technical", "account"]}},
        "required": ["team"],
    },
    idempotency_key="ticket-4821-route-v1",
    timeout_seconds=95,
)

if answer["status"] == "completed":
    print(answer["answer"]["team"])
elif answer["status"] in ("failed", "cancelled"):
    print("no answer:", answer["error_code"])  # e.g. invalid_structured_output
else:
    # queued or streaming: the first request under this key is still running.
    answer = reef.prompts.get_answer(answer["prompt_request_id"])

StructuredAnswer is a status-discriminated union. A string is sent as one user message; pass a list of PromptMessage for system or multi-turn input, and options (StructuredAskOptions) to choose the model or the execution policies.

The idempotency key makes the ask safe to retry. A retry under the same key with the same arguments returns the stored result without calling or billing the model again. The same key with different arguments fails with idempotency_conflict. When you leave out input_message_refs, the SDK derives them from the key, so a retry sends the same request.

Reef answers when the prompt ends, which can outlast the client's 30 second default timeout. Pass timeout_seconds of about 95 for slow models. A client timeout does not cancel the prompt: retry under the same key, or read it later with get_answer.

Read the cost of one prompt

cost = reef.usage.get_prompt_cost("support-product", answer["prompt_request_id"])
if not cost["cost_pending"] and cost["cost_usd"] is not None:
    print(cost["cost_usd"], cost["currency"])  # Decimal, USD

PromptCost holds the prompt's usage rows (items) and their total as a Decimal. The total is None while it is not known: before a queued prompt records usage, or while a row's cost awaits reconciliation with the provider (cost_pending). is_estimate marks a cost Reef estimated rather than read from the provider. The principal needs agent_budget:read. A prompt in another product or organization is not found.

Reef does not offer a per-request cost ceiling. A budget policy's hard_limit_usd refuses new prompts once the period's spend plus one reservation would pass it, but max_request_cost_usd is only the amount each prompt reserves: Reef does not stop a prompt that costs more.

Runtime requirements

  • Call the SDK from a product backend. Do not expose Reef credentials to browser code.
  • The principal needs agent_decision:execute for decisions and agent_prompt:send for structured asks.
  • The product needs an active OpenRouter provider configuration and an execution policy whose model policy requires the decisions capability.
  • Reuse an idempotency key only for the same request. Reef returns the stored result without a second provider call.

See Reef decision requests for policy setup, the HTTP contract, errors, accounting, and production verification evidence.

The client also exposes configuration, prompts, conversations, files, runs, approvals, tools, usage, memory, and evidence. Mutations require caller-owned idempotency keys. The SDK never accepts provider credentials and does not retry mutations outside Reef.

Metadata

Release files for reef-sdk 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reef-sdk 0.4.0
File Size Uploaded Provenance Actions
reef_sdk-0.4.0.tar.gz 22.4 kB Without provenance Details for reef_sdk-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for reef-sdk 0.4.0
File Interpreter ABI Platform Actions
reef_sdk-0.4.0-py3-none-any.whl Python 3 none any Details for reef_sdk-0.4.0-py3-none-any.whl

Total release size: 39.7 kB

Release files / reef_sdk-0.4.0.tar.gz

Download URL reef_sdk-0.4.0.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
619c30fda0a1d27d4ecc0b1d334e48484cc952d6a29b3d2a89c48c25e8a57701
BLAKE2b-256 checksum
How to use checksums
3a98fbb69f5f480a81b2d126314eb91f08371b21344ee136b6c3939aff34fb34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / reef_sdk-0.4.0-py3-none-any.whl

Download URL reef_sdk-0.4.0-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90bcb4c28bdb82dc2967ee648326bc8fc1a428fd424887176b32700112e9386f
BLAKE2b-256 checksum
How to use checksums
71791dbcead36193762a4cd2f6a8b9171c742a21abedda12931da922faea2dd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for reef-sdk 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page