Skip to content

Conversation

@aegeiger
Copy link
Owner

What does this PR do?

Includes all code to generate a llama_stack_client sdk using openapi-generator-cli directly from the llama-stack repo

Test Plan

After generating a client, uninstall the llama_stack_client package, and uv pip install ./client-sdks/openapi/sdks/python, then run integration tests.

@aegeiger aegeiger force-pushed the feature/release-0.4.x-openapi branch from d2a9f4e to 3c192d9 Compare January 1, 2026 16:20
@aegeiger aegeiger changed the title Feature/OpenAPI Generator for client SDK feat: OpenAPI Generator for client SDK Jan 4, 2026
@aegeiger aegeiger force-pushed the feature/release-0.4.x-openapi branch 2 times, most recently from 382b324 to 455510d Compare January 4, 2026 07:53
aegeiger and others added 6 commits January 4, 2026 12:39
Add comprehensive build tooling for generating the Python SDK from OpenAPI
specs with support for hierarchical API structures:

- build-hierarchical-sdk.sh: Main build script orchestrating the full pipeline
- generate-python-sdk.sh: OpenAPI Generator wrapper with custom config
- process_openapi_hierarchy.py: Extracts tag hierarchies and adds x-child-tags
- patch_api_hierarchy.py: Post-generation patching for nested API structure
- merge_stainless_to_openapi.py: Merges Stainless spec into OpenAPI Generator spec
- openapi-config.json: OpenAPI Generator configuration
- patches.yml: API hierarchy patches for LlamaStackClient wiring

This infrastructure enables generating SDKs with nested API access patterns
like client.chat.completions.create() while maintaining OpenAPI Generator
compatibility.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Enhance OpenAPI templates to support hierarchical API structure and
improved streaming:

Template Improvements:
- Add pascal_to_snake_case utility to deduplicate class-to-module conversion
- Add LlamaStackClient wrapper with nested API access (chat.completions.*)
- Add x-child-tags documentation showing nested API attributes
- Update examples to use LlamaStackClient instead of individual API classes
- Improve _create_event_stream for better SSE handling with proper typing

Model Template Enhancements:
- Enhance anyOf/oneOf deserialization with discriminator support
- Add fallback to from_dict for streaming chunks
- Use pascal_to_snake_case for consistent module resolution

Streaming Improvements:
- Add Stream template for server-sent events
- Fix return types and parameter passing in _create_event_stream
- Add proper decoder for streaming response types

This enables the SDK to support both flat (client.chat_completions.create)
and hierarchical (client.chat.completions.create) access patterns.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add async/await support to the generated SDK with full async versions
of all API clients:

- async_api_client.mustache: Async HTTP client with httpx
- async_api_response.mustache: Async response wrapper
- async_stream.mustache: Async streaming support for SSE

This allows users to use the SDK in async contexts with proper async/await
patterns while maintaining the same API surface as the synchronous client.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Export Agent and AgentEventLogger from lib/__init__.py
- Add tools/__init__.py to export get_oauth_token_for_mcp_server

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Complete the SDK template suite and fix related server/test issues:

Template Additions:
- Add _exceptions.mustache, _types.mustache, _version.mustache
- Update README templates with hierarchical API examples
- Enhance configuration.mustache with better defaults
- Update partial templates for consistency

Server Fixes:
- Fix error response format to match OpenAPI spec (remove wrapper)
- Update library_client for new SDK structure

Test Updates:
- Update integration tests to use new LlamaStackClient
- Fix imports and client initialization patterns
- Update embeddings, rerank, tools, and vector_io tests

Stainless Config:
- Update config for compatibility with OpenAPI Generator output

These changes complete the migration to the hierarchical SDK structure
while maintaining backward compatibility.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Linting fixes:
- UP047: Use modern type parameter syntax for generic functions
- UP038/UP040: Use X | Y syntax instead of Union/tuple in type hints
- C414: Remove unnecessary list() calls in sorted()
- RUF001: Replace ambiguous unicode character with ASCII
- F841: Remove unused variable
- F821: Add missing statistics import
- W291: Remove trailing whitespace

Removed templates/lib (duplicate of templates/python/lib)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@aegeiger aegeiger force-pushed the feature/release-0.4.x-openapi branch from 455510d to 6340d30 Compare January 4, 2026 14:46
aegeiger and others added 4 commits January 12, 2026 15:36
Fix bug in model_generic.mustache where dictionary field serialization
would skip falsy values (False, 0, "", [], {}) due to truthiness check.

The previous implementation used `if value:` which incorrectly filtered
out valid falsy values. This caused data loss when serializing models
with boolean False, integer 0, empty strings, or empty collections.

Changes:
- Replace truthiness check with explicit `is None` check
- Cache dictionary value in variable to avoid repeated lookups
- Preserve all valid values including falsy ones

Impact: Models with falsy values will now serialize correctly.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive HTTP exception handling and compatibility layer:

1. Add RateLimitException for HTTP 429 status codes
   - Raised automatically when server returns 429
   - Allows explicit handling of rate limit errors

2. Add httpx-style property aliases
   - message property (returns reason)
   - status_code property (returns status)
   - Provides compatibility with httpx exception interface

3. Add exception name aliases
   - BadRequestError, AuthenticationError, PermissionDeniedError, etc.
   - Maps to existing Exception classes (BadRequestException, etc.)
   - Allows consistent naming across urllib3 and httpx styles

4. Update package imports
   - Import from exceptions.py instead of _exceptions.py
   - Uses urllib3-based exceptions with added compatibility

Benefits:
- Explicit 429 rate limit error handling
- Code compatibility with both naming conventions
- Consistent exception interface across HTTP libraries

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Remove BadRequestException from exception handling tuples in vector store
tests. BadRequestException was never imported and is now an alias to
BadRequestError (defined in exceptions.py).

With the exception template changes, BadRequestError is sufficient as it
maps to BadRequestException internally.

Changes:
- Remove BadRequestException from error tuples (4 locations)
- Remove unused import statement
- Tests now catch BadRequestError and OpenAIBadRequestError only

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive comparison document between Stainless-generated and
OpenAPI Generator SDKs for the Llama Stack client.

Document covers:
- Package structure and organization
- Client initialization patterns
- API access patterns (hierarchical vs flat)
- Configuration approaches
- Union type handling differences
- HTTP client implementations (httpx vs urllib3)
- Exception handling
- Streaming support
- Feature parity analysis

Key findings:
- Both SDKs are functionally equivalent for core use cases
- OpenAPI Generator provides more traditional configuration patterns
- Stainless uses modern httpx, OpenAPI Generator uses urllib3
- Minor differences in union type deserialization
- Both support hierarchical API access

Helps developers understand trade-offs when choosing between SDK
generation approaches.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants