This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Opper AI Python SDK, an auto-generated client library built using Speakeasy from OpenAPI specifications. The SDK provides type-safe Python bindings for the Opper AI API, supporting functions, knowledge bases, datasets, embeddings, tracing, and analytics.
# Full regeneration (recommended)
make generate # Runs speakeasy, fixes params, applies schema patches
# Individual steps
make check-speakeasy # Verify speakeasy CLI is installed
make fix-input-params # Fix input_ parameters to input
make apply-schema-patch # Add Pydantic schema conversion handling
make test-patch # Verify patches were applied correctly# Run tests (if test.py exists)
make test
# Lint and type checking
pylint src/ # Lint with project-specific config
mypy src/ # Type checking with mypymake clean # Reset to clean git state
make full # Clean + generate + test
make preview-changes # Show what would change without applyingThis project uses Speakeasy to auto-generate SDK code from OpenAPI specs, with a custom patching system to preserve important modifications:
- Parameter Name Fixing: Converts
input_parameters toinputfor API consistency - Schema Conversion Patches: Adds Pydantic model → JSON schema conversion to SDK methods
- Automated Application: All patches applied via
make generate
The project uses custom GitHub Actions workflows (not the standard Speakeasy workflows) due to the custom patching requirements:
generate-sdk.yml: Automated SDK generation (manual trigger or weekly schedule)release.yml: Automated PyPI releases when version changes inpyproject.tomlvalidate-pr.yml: PR validation and testing
src/opperai/sdk.py: Main SDK entry point withcall,call_async,stream,stream_asyncmethodssrc/opperai/functions.py: Function management (create, update, delete, call)src/opperai/knowledge.py: Knowledge base operationssrc/opperai/datasets.py: Dataset management and queryingsrc/opperai/spans.py/traces.py: Observability and tracingsrc/opperai/models/: Generated Pydantic models for all API types
The patching system adds this code block to SDK methods:
# region convert-pydantic-schemas
if input_schema is not UNSET and hasattr(input_schema, 'model_json_schema'):
input_schema = input_schema.model_json_schema()
if output_schema is not UNSET and hasattr(output_schema, 'model_json_schema'):
output_schema = output_schema.model_json_schema()
# endregion convert-pydantic-schemasThis allows users to pass either Pydantic model classes (auto-converted) or plain dictionaries.
- Poetry: Primary dependency management (
pyproject.toml,poetry.lock) - UV: Alternative fast Python package installer (
uv.lock) - Core Dependencies: httpx, pydantic, httpcore
pyproject.toml: Project metadata, dependencies, tool configurationpylintrc: Comprehensive linting rules with custom overrides.github/workflows/sdk_generation.yaml: Automated SDK generation via SpeakeasyMakefile: All development automation targets
scripts/apply_schema_patch.py: Python script that applies schema conversion patchesSPEAKEASY_PATCH_README.md: Detailed documentation of the patching system
- Generated: Everything in
src/opperai/(except custom patches) - Custom: Makefile, scripts/, patch system, configuration files
- Examples:
examples/directory with usage patterns for all SDK features
The project follows this workflow for updates and releases:
-
SDK Generation:
- Manual: Go to GitHub Actions → "Generate SDK" → Run workflow
- Automatic: Runs weekly on Mondays at 9 AM UTC
- Creates PR with updated SDK code if changes detected
-
Version Management:
- Speakeasy automatically updates version in
pyproject.tomlduring generation - Starting from version
2.0.0(manually set for this custom workflow transition) - Future versions managed by Speakeasy following semantic versioning
- Version changes in merged PRs automatically trigger releases
- Speakeasy automatically updates version in
-
Automated Release:
- Push/merge to
mainwith version change triggersrelease.yml - Builds package with UV
- Publishes to PyPI automatically
- Creates GitHub release with changelog
- Push/merge to
-
Manual Release (if needed):
- Use "Release to PyPI" workflow in GitHub Actions
- Typically only needed for hotfixes or urgent releases
- Most releases happen automatically via SDK generation PRs
For the workflows to function, these GitHub secrets must be configured:
SPEAKEASY_API_KEY: For SDK generationPYPI_API_TOKEN: For publishing to PyPI (use trusted publishing if possible)
- Never manually edit files in
src/opperai/- changes will be overwritten - Always use
make generateinstead ofspeakeasy rundirectly - Patches are idempotent - safe to run multiple times
- Test patches with
make test-patchafter structural changes
- SDK supports both Pydantic models and plain dictionaries for schemas
- Pydantic models are automatically converted to JSON schema via patches
- Use
MyModel.model_json_schema()when working with schemas manually
- Monitor Speakeasy updates that might change code structure
- Update patch patterns in
apply_schema_patch.pyif SDK structure changes - Maintain backward compatibility when modifying patch system
- Test examples in
examples/directory after regeneration