Skip to content

Commit 3c192d9

Browse files
aegeigerclaude
andcommitted
client-sdk: add templates and server fixes
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>
1 parent 270dfea commit 3c192d9

24 files changed

+721
-100
lines changed

client-sdks/openapi/templates/python/README.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,3 @@ Execute `pytest` to run the tests.
5858
Please follow the [installation procedure](#installation--usage) and then run the following:
5959

6060
{{> common_README }}
61-

client-sdks/openapi/templates/python/README_onlypackage.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,3 @@ In your own code, to use this library to connect and interact with {{{projectNam
4848
you can run the following:
4949

5050
{{> common_README }}
51-
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the terms described in the LICENSE file in
5+
# the root directory of this source tree.
6+
7+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
8+
9+
from __future__ import annotations
10+
11+
from typing_extensions import Literal
12+
13+
import httpx
14+
15+
__all__ = [
16+
"BadRequestError",
17+
"AuthenticationError",
18+
"PermissionDeniedError",
19+
"NotFoundError",
20+
"ConflictError",
21+
"UnprocessableEntityError",
22+
"RateLimitError",
23+
"InternalServerError",
24+
]
25+
26+
27+
class LlamaStackClientError(Exception):
28+
pass
29+
30+
31+
class APIError(LlamaStackClientError):
32+
message: str
33+
request: httpx.Request
34+
35+
body: object | None
36+
"""The API response body.
37+
38+
If the API responded with a valid JSON structure then this property will be the
39+
decoded result.
40+
41+
If it isn't a valid JSON structure then this will be the raw response.
42+
43+
If there was no response associated with this error then it will be `None`.
44+
"""
45+
46+
def __init__(self, message: str, request: httpx.Request, *, body: object | None) -> None: # noqa: ARG002
47+
super().__init__(message)
48+
self.request = request
49+
self.message = message
50+
self.body = body
51+
52+
53+
class APIResponseValidationError(APIError):
54+
response: httpx.Response
55+
status_code: int
56+
57+
def __init__(self, response: httpx.Response, body: object | None, *, message: str | None = None) -> None:
58+
super().__init__(message or "Data returned by API invalid for expected schema.", response.request, body=body)
59+
self.response = response
60+
self.status_code = response.status_code
61+
62+
63+
class APIStatusError(APIError):
64+
"""Raised when an API response has a status code of 4xx or 5xx."""
65+
66+
response: httpx.Response
67+
status_code: int
68+
69+
def __init__(self, message: str, *, response: httpx.Response, body: object | None) -> None:
70+
super().__init__(message, response.request, body=body)
71+
self.response = response
72+
self.status_code = response.status_code
73+
74+
75+
class APIConnectionError(APIError):
76+
def __init__(self, *, message: str = "Connection error.", request: httpx.Request) -> None:
77+
super().__init__(message, request, body=None)
78+
79+
80+
class APITimeoutError(APIConnectionError):
81+
def __init__(self, request: httpx.Request) -> None:
82+
super().__init__(message="Request timed out.", request=request)
83+
84+
85+
class BadRequestError(APIStatusError):
86+
status_code: Literal[400] = 400 # pyright: ignore[reportIncompatibleVariableOverride]
87+
88+
89+
class AuthenticationError(APIStatusError):
90+
status_code: Literal[401] = 401 # pyright: ignore[reportIncompatibleVariableOverride]
91+
92+
93+
class PermissionDeniedError(APIStatusError):
94+
status_code: Literal[403] = 403 # pyright: ignore[reportIncompatibleVariableOverride]
95+
96+
97+
class NotFoundError(APIStatusError):
98+
status_code: Literal[404] = 404 # pyright: ignore[reportIncompatibleVariableOverride]
99+
100+
101+
class ConflictError(APIStatusError):
102+
status_code: Literal[409] = 409 # pyright: ignore[reportIncompatibleVariableOverride]
103+
104+
105+
class UnprocessableEntityError(APIStatusError):
106+
status_code: Literal[422] = 422 # pyright: ignore[reportIncompatibleVariableOverride]
107+
108+
109+
class RateLimitError(APIStatusError):
110+
status_code: Literal[429] = 429 # pyright: ignore[reportIncompatibleVariableOverride]
111+
112+
113+
class InternalServerError(APIStatusError):
114+
pass

0 commit comments

Comments
 (0)