From 5bbac1db3f3904cc0c6e1dd99cc75832199f8b62 Mon Sep 17 00:00:00 2001 From: hasangzl <21182018+hasangzl@users.noreply.github.com> Date: Tue, 20 Oct 2026 18:52:15 +0000 Subject: [PATCH] feat: regenerate SDK client core from Otari OpenAPI spec --- src/otari/_client/__init__.py | 4 + src/otari/_client/api/messages_api.py | 18 ++- src/otari/_client/models/__init__.py | 2 + src/otari/_client/models/anthropic_error.py | 90 ++++++++++++++ .../models/anthropic_error_response.py | 111 ++++++++++++++++++ 5 files changed, 219 insertions(+), 6 deletions(-) create mode 100644 src/otari/_client/models/anthropic_error.py create mode 100644 src/otari/_client/models/anthropic_error_response.py diff --git a/src/otari/_client/__init__.py b/src/otari/_client/__init__.py index 8fddd2b6..e8eb2935 100644 --- a/src/otari/_client/__init__.py +++ b/src/otari/_client/__init__.py @@ -120,6 +120,8 @@ "AliasResponse", "AllocationHealthResponse", "Annotations", + "AnthropicError", + "AnthropicErrorResponse", "AnthropicFileDeleted", "AnthropicFileList", "AnthropicFileMetadata", @@ -892,6 +894,8 @@ from otari._client.models.alias_response import AliasResponse as AliasResponse from otari._client.models.allocation_health_response import AllocationHealthResponse as AllocationHealthResponse from otari._client.models.annotations import Annotations as Annotations +from otari._client.models.anthropic_error import AnthropicError as AnthropicError +from otari._client.models.anthropic_error_response import AnthropicErrorResponse as AnthropicErrorResponse from otari._client.models.anthropic_file_deleted import AnthropicFileDeleted as AnthropicFileDeleted from otari._client.models.anthropic_file_list import AnthropicFileList as AnthropicFileList from otari._client.models.anthropic_file_metadata import AnthropicFileMetadata as AnthropicFileMetadata diff --git a/src/otari/_client/api/messages_api.py b/src/otari/_client/api/messages_api.py index 3924ca0f..f4e7a2b3 100644 --- a/src/otari/_client/api/messages_api.py +++ b/src/otari/_client/api/messages_api.py @@ -96,7 +96,8 @@ def messages_count_message_tokens( _response_types_map: Dict[str, Optional[str]] = { '200': "CountTokensResponse", - '422': "HTTPValidationError", + '4XX': "AnthropicErrorResponse", + '5XX': "AnthropicErrorResponse", } response_data = self.api_client.call_api( *_param, @@ -164,7 +165,8 @@ def messages_count_message_tokens_with_http_info( _response_types_map: Dict[str, Optional[str]] = { '200': "CountTokensResponse", - '422': "HTTPValidationError", + '4XX': "AnthropicErrorResponse", + '5XX': "AnthropicErrorResponse", } response_data = self.api_client.call_api( *_param, @@ -232,7 +234,8 @@ def messages_count_message_tokens_without_preload_content( _response_types_map: Dict[str, Optional[str]] = { '200': "CountTokensResponse", - '422': "HTTPValidationError", + '4XX': "AnthropicErrorResponse", + '5XX': "AnthropicErrorResponse", } response_data = self.api_client.call_api( *_param, @@ -382,7 +385,8 @@ def messages_create_message( _response_types_map: Dict[str, Optional[str]] = { '200': "MessageResponse", - '422': "HTTPValidationError", + '4XX': "AnthropicErrorResponse", + '5XX': "AnthropicErrorResponse", } response_data = self.api_client.call_api( *_param, @@ -458,7 +462,8 @@ def messages_create_message_with_http_info( _response_types_map: Dict[str, Optional[str]] = { '200': "MessageResponse", - '422': "HTTPValidationError", + '4XX': "AnthropicErrorResponse", + '5XX': "AnthropicErrorResponse", } response_data = self.api_client.call_api( *_param, @@ -534,7 +539,8 @@ def messages_create_message_without_preload_content( _response_types_map: Dict[str, Optional[str]] = { '200': "MessageResponse", - '422': "HTTPValidationError", + '4XX': "AnthropicErrorResponse", + '5XX': "AnthropicErrorResponse", } response_data = self.api_client.call_api( *_param, diff --git a/src/otari/_client/models/__init__.py b/src/otari/_client/models/__init__.py index ddfd8937..c2ff44f1 100644 --- a/src/otari/_client/models/__init__.py +++ b/src/otari/_client/models/__init__.py @@ -43,6 +43,8 @@ from otari._client.models.alias_response import AliasResponse from otari._client.models.allocation_health_response import AllocationHealthResponse from otari._client.models.annotations import Annotations +from otari._client.models.anthropic_error import AnthropicError +from otari._client.models.anthropic_error_response import AnthropicErrorResponse from otari._client.models.anthropic_file_deleted import AnthropicFileDeleted from otari._client.models.anthropic_file_list import AnthropicFileList from otari._client.models.anthropic_file_metadata import AnthropicFileMetadata diff --git a/src/otari/_client/models/anthropic_error.py b/src/otari/_client/models/anthropic_error.py new file mode 100644 index 00000000..ecd00a49 --- /dev/null +++ b/src/otari/_client/models/anthropic_error.py @@ -0,0 +1,90 @@ +# coding: utf-8 + +""" + otari + + Otari, an OpenAI-compatible LLM gateway with API key management + + The version of the OpenAPI document: 0.0.0-dev + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List +from typing import Optional, Set +from typing_extensions import Self +from pydantic_core import to_jsonable_python + +class AnthropicError(BaseModel): + """ + What went wrong, in Anthropic's terms. + """ # noqa: E501 + message: StrictStr + type: StrictStr = Field(description="Anthropic's error type, such as `invalid_request_error` or `rate_limit_error`.") + __properties: ClassVar[List[str]] = ["message", "type"] + + model_config = ConfigDict( + validate_by_name=True, + validate_by_alias=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(to_jsonable_python(self.to_dict())) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of AnthropicError from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([ + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of AnthropicError from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "message": obj.get("message"), + "type": obj.get("type") + }) + return _obj + + diff --git a/src/otari/_client/models/anthropic_error_response.py b/src/otari/_client/models/anthropic_error_response.py new file mode 100644 index 00000000..04bdc91b --- /dev/null +++ b/src/otari/_client/models/anthropic_error_response.py @@ -0,0 +1,111 @@ +# coding: utf-8 + +""" + otari + + Otari, an OpenAI-compatible LLM gateway with API key management + + The version of the OpenAPI document: 0.0.0-dev + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from typing import Any, ClassVar, Dict, List, Optional +from otari._client.models.anthropic_error import AnthropicError +from typing import Optional, Set +from typing_extensions import Self +from pydantic_core import to_jsonable_python + +class AnthropicErrorResponse(BaseModel): + """ + Anthropic's error envelope, which every error on a Messages route is answered in. + """ # noqa: E501 + code: Optional[StrictStr] = Field(default=None, description="The refusal's `Otari-Error-Code`, where it has one.") + error: AnthropicError + type: Optional[StrictStr] = 'error' + __properties: ClassVar[List[str]] = ["code", "error", "type"] + + @field_validator('type') + def type_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(['error']): + raise ValueError("must be one of enum values ('error')") + return value + + model_config = ConfigDict( + validate_by_name=True, + validate_by_alias=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(to_jsonable_python(self.to_dict())) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of AnthropicErrorResponse from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([ + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of error + if self.error: + _dict['error'] = self.error.to_dict() + # set to None if code (nullable) is None + # and model_fields_set contains the field + if self.code is None and "code" in self.model_fields_set: + _dict['code'] = None + + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of AnthropicErrorResponse from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "code": obj.get("code"), + "error": AnthropicError.from_dict(obj["error"]) if obj.get("error") is not None else None, + "type": obj.get("type") if obj.get("type") is not None else 'error' + }) + return _obj + +