Skip to main content

API Reference

Complete reference documentation for all classes, methods, and exceptions in the Claro Python SDK.

BaytClient

The main client class for interacting with the Claro API.

Constructor

Parameters: Raises:
  • ValueError - If no API key is provided and BAYT_API_KEY is not set
  • ValueError - If API key format is invalid (must start with sk_)
Example:

get_prompt()

Fetch a prompt by its package name.
Parameters: Returns:
  • Prompt - Prompt object with content and metadata
Raises:
  • BaytValidationError - If package name format is invalid
  • BaytAuthError - If authentication fails (401, 403)
  • BaytNotFoundError - If prompt is not found (404)
  • BaytRateLimitError - If rate limit is exceeded after retries (429)
  • BaytAPIError - For other API errors
Example:

list_prompts()

List prompts accessible to the authenticated user.
Parameters: Returns: Dictionary with the following keys:
  • prompts (List[Prompt]) - List of Prompt objects
  • cursor (str) - Cursor for next page
  • hasMore (bool) - True if more pages available
Raises:
  • BaytValidationError - If limit is not between 1 and 100
  • BaytAuthError - If authentication fails
  • BaytRateLimitError - If rate limit is exceeded
  • BaytAPIError - For other API errors
Example:

download_context_file()

Download a context file and return its content as bytes.
Parameters: Returns:
  • bytes - File content
Raises:
  • BaytAuthError - If authentication fails
  • BaytNotFoundError - If context item is not found
  • BaytValidationError - If context item is not a file type
  • BaytAPIError - For other API errors
Example:

get_context_download_url()

Get a signed download URL for a context file.
Parameters: Returns: Dictionary with the following keys:
  • url (str) - Signed download URL
  • expiresIn (int) - Seconds until URL expires
Raises:
  • BaytAuthError - If authentication fails
  • BaytNotFoundError - If context item is not found
  • BaytValidationError - If context item is not a file type
  • BaytAPIError - For other API errors
Example:

Prompt

Represents a Claro prompt with all its content and metadata.

Properties

Methods

has_context()

Check if the prompt has any context items.
Returns:
  • bool - True if prompt has context items
Example:

has_system_prompt()

Check if the prompt has a system prompt.
Returns:
  • bool - True if prompt has a system prompt

has_critique_prompt()

Check if the prompt has a critique prompt.
Returns:
  • bool - True if prompt has a critique prompt

get_file_contexts()

Get only file-type context items.
Returns:
  • List[ContextItem] - List of file context items
Example:

get_url_contexts()

Get only URL-type context items.
Returns:
  • List[ContextItem] - List of URL context items
Example:

extract_variables()

Extract variables from prompt content with optional type hints.
Returns: List of dictionaries with the following keys:
  • name (str) - Variable name
  • type (str, optional) - Variable type
  • description (str, optional) - Variable description
Example:

validate_variables()

Validate provided variables against expected variables.
Parameters: Returns:
  • Dict[str, str] - Validation errors (empty if all valid)
Example:

to_dict()

Get the full dictionary representation of the prompt.
Returns:
  • Dict[str, Any] - Dictionary representation

Dictionary-Style Access

Prompts support dictionary-style access:

ContextItem

Represents a context item (file or URL) attached to a prompt.

Properties

Methods

is_file()

Check if this context item is a file.
Returns:
  • bool - True if type is “file”

is_url()

Check if this context item is a URL.
Returns:
  • bool - True if type is “url”

to_dict()

Get the full dictionary representation of the context item.
Returns:
  • Dict[str, Any] - Dictionary representation
Example:

Exceptions

All exceptions inherit from BaytAPIError.

BaytAPIError

Base exception for all SDK errors.
Usage:

BaytAuthError

Authentication or authorization error (HTTP 401, 403).
Common causes:
  • Invalid API key
  • Expired API key
  • Insufficient permissions
  • Workspace access denied
Usage:

BaytNotFoundError

Resource not found error (HTTP 404).
Common causes:
  • Incorrect package name
  • Wrong version number
  • Prompt deleted
  • No access to workspace
Usage:

BaytRateLimitError

Rate limit exceeded error (HTTP 429).
Raised only after all automatic retries are exhausted. Usage:

BaytValidationError

Invalid request parameters (HTTP 400).
Common causes:
  • Invalid package name format
  • Out of range parameters
  • Missing required fields
Usage:

Type Hints

The SDK is fully typed. Import types for type checking:

Complete Example

Next Steps

Quickstart

Get started with the SDK

Working with Prompts

Learn about prompts in detail

Error Handling

Handle errors gracefully

Advanced Features

Optimize performance