byteplussdk-arkruntime 3.0.64__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. byteplussdk_arkruntime-3.0.64.dist-info/METADATA +36 -0
  2. byteplussdk_arkruntime-3.0.64.dist-info/RECORD +240 -0
  3. byteplussdk_arkruntime-3.0.64.dist-info/WHEEL +5 -0
  4. byteplussdk_arkruntime-3.0.64.dist-info/licenses/LICENSE.txt +203 -0
  5. byteplussdk_arkruntime-3.0.64.dist-info/top_level.txt +1 -0
  6. byteplussdkarkruntime/__init__.py +7 -0
  7. byteplussdkarkruntime/_base_client.py +1439 -0
  8. byteplussdkarkruntime/_client.py +570 -0
  9. byteplussdkarkruntime/_compat.py +245 -0
  10. byteplussdkarkruntime/_constants.py +43 -0
  11. byteplussdkarkruntime/_exceptions.py +202 -0
  12. byteplussdkarkruntime/_files.py +149 -0
  13. byteplussdkarkruntime/_legacy_response.py +451 -0
  14. byteplussdkarkruntime/_models.py +734 -0
  15. byteplussdkarkruntime/_qs.py +168 -0
  16. byteplussdkarkruntime/_request_options.py +117 -0
  17. byteplussdkarkruntime/_resource.py +47 -0
  18. byteplussdkarkruntime/_response.py +615 -0
  19. byteplussdkarkruntime/_streaming.py +470 -0
  20. byteplussdkarkruntime/_types.py +210 -0
  21. byteplussdkarkruntime/_utils/__init__.py +58 -0
  22. byteplussdkarkruntime/_utils/_key_agreement.py +207 -0
  23. byteplussdkarkruntime/_utils/_logs.py +24 -0
  24. byteplussdkarkruntime/_utils/_model_breaker.py +83 -0
  25. byteplussdkarkruntime/_utils/_streams.py +12 -0
  26. byteplussdkarkruntime/_utils/_transform.py +489 -0
  27. byteplussdkarkruntime/_utils/_typing.py +171 -0
  28. byteplussdkarkruntime/_utils/_utils.py +497 -0
  29. byteplussdkarkruntime/common/__init__.py +14 -0
  30. byteplussdkarkruntime/common/_parsing/__init__.py +22 -0
  31. byteplussdkarkruntime/common/_parsing/_completions.py +290 -0
  32. byteplussdkarkruntime/common/_parsing/_responses.py +189 -0
  33. byteplussdkarkruntime/common/_pydantic.py +192 -0
  34. byteplussdkarkruntime/common/_tools.py +67 -0
  35. byteplussdkarkruntime/common/streaming/__init__.py +12 -0
  36. byteplussdkarkruntime/common/streaming/_deltas.py +86 -0
  37. byteplussdkarkruntime/common/streaming/chat/__init__.py +33 -0
  38. byteplussdkarkruntime/common/streaming/chat/_completions.py +772 -0
  39. byteplussdkarkruntime/common/streaming/chat/_events.py +103 -0
  40. byteplussdkarkruntime/common/streaming/chat/_types.py +36 -0
  41. byteplussdkarkruntime/pagination.py +134 -0
  42. byteplussdkarkruntime/resources/__init__.py +48 -0
  43. byteplussdkarkruntime/resources/batch/__init__.py +3 -0
  44. byteplussdkarkruntime/resources/batch/_utils.py +155 -0
  45. byteplussdkarkruntime/resources/batch/batch.py +37 -0
  46. byteplussdkarkruntime/resources/batch/chat/__init__.py +3 -0
  47. byteplussdkarkruntime/resources/batch/chat/chat.py +19 -0
  48. byteplussdkarkruntime/resources/batch/chat/completions.py +329 -0
  49. byteplussdkarkruntime/resources/batch/embeddings.py +105 -0
  50. byteplussdkarkruntime/resources/batch/multimodal_embeddings.py +111 -0
  51. byteplussdkarkruntime/resources/batch_chat/__init__.py +3 -0
  52. byteplussdkarkruntime/resources/batch_chat/chat.py +21 -0
  53. byteplussdkarkruntime/resources/batch_chat/completions.py +328 -0
  54. byteplussdkarkruntime/resources/beta/__init__.py +12 -0
  55. byteplussdkarkruntime/resources/beta/beta.py +81 -0
  56. byteplussdkarkruntime/resources/beta/chat/__init__.py +21 -0
  57. byteplussdkarkruntime/resources/beta/chat/chat.py +31 -0
  58. byteplussdkarkruntime/resources/beta/chat/completions.py +454 -0
  59. byteplussdkarkruntime/resources/chat/__init__.py +3 -0
  60. byteplussdkarkruntime/resources/chat/chat.py +21 -0
  61. byteplussdkarkruntime/resources/chat/completions.py +258 -0
  62. byteplussdkarkruntime/resources/content_generation/__init__.py +6 -0
  63. byteplussdkarkruntime/resources/content_generation/content_generation.py +17 -0
  64. byteplussdkarkruntime/resources/content_generation/tasks.py +348 -0
  65. byteplussdkarkruntime/resources/context/__init__.py +3 -0
  66. byteplussdkarkruntime/resources/context/completions.py +221 -0
  67. byteplussdkarkruntime/resources/context/context.py +98 -0
  68. byteplussdkarkruntime/resources/embeddings.py +110 -0
  69. byteplussdkarkruntime/resources/encryption.py +215 -0
  70. byteplussdkarkruntime/resources/files.py +592 -0
  71. byteplussdkarkruntime/resources/images/__init__.py +6 -0
  72. byteplussdkarkruntime/resources/images/images.py +335 -0
  73. byteplussdkarkruntime/resources/multimodal_embeddings.py +113 -0
  74. byteplussdkarkruntime/resources/responses/__init__.py +16 -0
  75. byteplussdkarkruntime/resources/responses/input_items.py +248 -0
  76. byteplussdkarkruntime/resources/responses/responses.py +417 -0
  77. byteplussdkarkruntime/types/__init__.py +28 -0
  78. byteplussdkarkruntime/types/chat/__init__.py +78 -0
  79. byteplussdkarkruntime/types/chat/chat_completion.py +93 -0
  80. byteplussdkarkruntime/types/chat/chat_completion_assistant_message_param.py +61 -0
  81. byteplussdkarkruntime/types/chat/chat_completion_audio.py +22 -0
  82. byteplussdkarkruntime/types/chat/chat_completion_chunk.py +165 -0
  83. byteplussdkarkruntime/types/chat/chat_completion_content_part_image_param.py +20 -0
  84. byteplussdkarkruntime/types/chat/chat_completion_content_part_param.py +30 -0
  85. byteplussdkarkruntime/types/chat/chat_completion_content_part_text_param.py +13 -0
  86. byteplussdkarkruntime/types/chat/chat_completion_content_part_video_param.py +32 -0
  87. byteplussdkarkruntime/types/chat/chat_completion_function_call_option_param.py +10 -0
  88. byteplussdkarkruntime/types/chat/chat_completion_function_message_param.py +17 -0
  89. byteplussdkarkruntime/types/chat/chat_completion_message.py +56 -0
  90. byteplussdkarkruntime/types/chat/chat_completion_message_param.py +19 -0
  91. byteplussdkarkruntime/types/chat/chat_completion_message_tool_call.py +29 -0
  92. byteplussdkarkruntime/types/chat/chat_completion_message_tool_call_param.py +29 -0
  93. byteplussdkarkruntime/types/chat/chat_completion_named_tool_choice_param.py +17 -0
  94. byteplussdkarkruntime/types/chat/chat_completion_role.py +5 -0
  95. byteplussdkarkruntime/types/chat/chat_completion_stream_options_param.py +19 -0
  96. byteplussdkarkruntime/types/chat/chat_completion_system_message_param.py +34 -0
  97. byteplussdkarkruntime/types/chat/chat_completion_token_logprob.py +55 -0
  98. byteplussdkarkruntime/types/chat/chat_completion_tool_choice_option_param.py +12 -0
  99. byteplussdkarkruntime/types/chat/chat_completion_tool_message_param.py +37 -0
  100. byteplussdkarkruntime/types/chat/chat_completion_tool_param.py +14 -0
  101. byteplussdkarkruntime/types/chat/chat_completion_user_message_param.py +34 -0
  102. byteplussdkarkruntime/types/chat/completion_create_params.py +258 -0
  103. byteplussdkarkruntime/types/chat/parsed_chat_completion.py +52 -0
  104. byteplussdkarkruntime/types/chat/parsed_function_tool_call.py +34 -0
  105. byteplussdkarkruntime/types/completion_usage.py +33 -0
  106. byteplussdkarkruntime/types/content_generation/__init__.py +0 -0
  107. byteplussdkarkruntime/types/content_generation/content_generation_task.py +106 -0
  108. byteplussdkarkruntime/types/content_generation/content_generation_task_id.py +11 -0
  109. byteplussdkarkruntime/types/content_generation/create_task_content_param.py +72 -0
  110. byteplussdkarkruntime/types/content_generation/list_content_generation_tasks_response.py +24 -0
  111. byteplussdkarkruntime/types/context/__init__.py +8 -0
  112. byteplussdkarkruntime/types/context/context_chat_completion.py +33 -0
  113. byteplussdkarkruntime/types/context/context_chat_completion_chunk.py +41 -0
  114. byteplussdkarkruntime/types/context/context_create_params.py +37 -0
  115. byteplussdkarkruntime/types/context/create_context_response.py +25 -0
  116. byteplussdkarkruntime/types/context/truncation_strategy.py +13 -0
  117. byteplussdkarkruntime/types/create_embedding_response.py +36 -0
  118. byteplussdkarkruntime/types/embedding.py +21 -0
  119. byteplussdkarkruntime/types/file_create_params.py +49 -0
  120. byteplussdkarkruntime/types/file_deleted.py +24 -0
  121. byteplussdkarkruntime/types/file_list_params.py +43 -0
  122. byteplussdkarkruntime/types/file_object.py +69 -0
  123. byteplussdkarkruntime/types/file_purpose.py +16 -0
  124. byteplussdkarkruntime/types/images/__init__.py +3 -0
  125. byteplussdkarkruntime/types/images/image_gen_completed_event.py +59 -0
  126. byteplussdkarkruntime/types/images/image_gen_generating_event.py +53 -0
  127. byteplussdkarkruntime/types/images/image_gen_stream_event.py +24 -0
  128. byteplussdkarkruntime/types/images/images.py +99 -0
  129. byteplussdkarkruntime/types/multimodal_embedding/__init__.py +15 -0
  130. byteplussdkarkruntime/types/multimodal_embedding/embedding_content_part_image_param.py +17 -0
  131. byteplussdkarkruntime/types/multimodal_embedding/embedding_content_part_text_param.py +13 -0
  132. byteplussdkarkruntime/types/multimodal_embedding/embedding_data.py +15 -0
  133. byteplussdkarkruntime/types/multimodal_embedding/embedding_input.py +12 -0
  134. byteplussdkarkruntime/types/multimodal_embedding/embedding_response.py +29 -0
  135. byteplussdkarkruntime/types/multimodal_embedding/embedding_usage.py +23 -0
  136. byteplussdkarkruntime/types/responses/__init__.py +133 -0
  137. byteplussdkarkruntime/types/responses/easy_input_message.py +36 -0
  138. byteplussdkarkruntime/types/responses/easy_input_message_param.py +37 -0
  139. byteplussdkarkruntime/types/responses/function_tool.py +35 -0
  140. byteplussdkarkruntime/types/responses/function_tool_param.py +35 -0
  141. byteplussdkarkruntime/types/responses/input_item_list_params.py +47 -0
  142. byteplussdkarkruntime/types/responses/mcp_input_item_param.py +109 -0
  143. byteplussdkarkruntime/types/responses/mcp_tool.py +80 -0
  144. byteplussdkarkruntime/types/responses/mcp_tool_param.py +78 -0
  145. byteplussdkarkruntime/types/responses/response.py +152 -0
  146. byteplussdkarkruntime/types/responses/response_annotation_added_event.py +36 -0
  147. byteplussdkarkruntime/types/responses/response_caching.py +25 -0
  148. byteplussdkarkruntime/types/responses/response_caching_param.py +22 -0
  149. byteplussdkarkruntime/types/responses/response_completed_event.py +26 -0
  150. byteplussdkarkruntime/types/responses/response_content_part_added_event.py +39 -0
  151. byteplussdkarkruntime/types/responses/response_content_part_done_event.py +39 -0
  152. byteplussdkarkruntime/types/responses/response_create_params.py +26 -0
  153. byteplussdkarkruntime/types/responses/response_created_event.py +26 -0
  154. byteplussdkarkruntime/types/responses/response_error.py +25 -0
  155. byteplussdkarkruntime/types/responses/response_error_event.py +32 -0
  156. byteplussdkarkruntime/types/responses/response_failed_event.py +26 -0
  157. byteplussdkarkruntime/types/responses/response_format_text_config.py +25 -0
  158. byteplussdkarkruntime/types/responses/response_format_text_config_param.py +25 -0
  159. byteplussdkarkruntime/types/responses/response_function_call_arguments_delta_event.py +33 -0
  160. byteplussdkarkruntime/types/responses/response_function_call_arguments_done_event.py +30 -0
  161. byteplussdkarkruntime/types/responses/response_function_tool_call.py +42 -0
  162. byteplussdkarkruntime/types/responses/response_function_tool_call_item.py +20 -0
  163. byteplussdkarkruntime/types/responses/response_function_tool_call_output_item.py +39 -0
  164. byteplussdkarkruntime/types/responses/response_function_tool_call_param.py +31 -0
  165. byteplussdkarkruntime/types/responses/response_in_progress_event.py +26 -0
  166. byteplussdkarkruntime/types/responses/response_includable.py +19 -0
  167. byteplussdkarkruntime/types/responses/response_incomplete_details.py +30 -0
  168. byteplussdkarkruntime/types/responses/response_incomplete_event.py +26 -0
  169. byteplussdkarkruntime/types/responses/response_input_content.py +24 -0
  170. byteplussdkarkruntime/types/responses/response_input_content_param.py +23 -0
  171. byteplussdkarkruntime/types/responses/response_input_image.py +38 -0
  172. byteplussdkarkruntime/types/responses/response_input_image_param.py +42 -0
  173. byteplussdkarkruntime/types/responses/response_input_image_pixel_limit_param.py +29 -0
  174. byteplussdkarkruntime/types/responses/response_input_message_content_list.py +20 -0
  175. byteplussdkarkruntime/types/responses/response_input_message_content_list_param.py +26 -0
  176. byteplussdkarkruntime/types/responses/response_input_message_item.py +43 -0
  177. byteplussdkarkruntime/types/responses/response_input_param.py +51 -0
  178. byteplussdkarkruntime/types/responses/response_input_text.py +25 -0
  179. byteplussdkarkruntime/types/responses/response_input_text_param.py +25 -0
  180. byteplussdkarkruntime/types/responses/response_input_video_param.py +34 -0
  181. byteplussdkarkruntime/types/responses/response_item.py +40 -0
  182. byteplussdkarkruntime/types/responses/response_item_list.py +36 -0
  183. byteplussdkarkruntime/types/responses/response_mcp_call_arguments_delta_event.py +37 -0
  184. byteplussdkarkruntime/types/responses/response_mcp_call_arguments_done_event.py +34 -0
  185. byteplussdkarkruntime/types/responses/response_mcp_call_completed_event.py +31 -0
  186. byteplussdkarkruntime/types/responses/response_mcp_call_failed_event.py +31 -0
  187. byteplussdkarkruntime/types/responses/response_mcp_call_in_progress_event.py +31 -0
  188. byteplussdkarkruntime/types/responses/response_mcp_item.py +110 -0
  189. byteplussdkarkruntime/types/responses/response_mcp_list_tools_completed_event.py +31 -0
  190. byteplussdkarkruntime/types/responses/response_mcp_list_tools_failed_event.py +31 -0
  191. byteplussdkarkruntime/types/responses/response_mcp_list_tools_in_progress_event.py +31 -0
  192. byteplussdkarkruntime/types/responses/response_output_item.py +36 -0
  193. byteplussdkarkruntime/types/responses/response_output_item_added_event.py +29 -0
  194. byteplussdkarkruntime/types/responses/response_output_item_done_event.py +29 -0
  195. byteplussdkarkruntime/types/responses/response_output_message.py +43 -0
  196. byteplussdkarkruntime/types/responses/response_output_text.py +61 -0
  197. byteplussdkarkruntime/types/responses/response_output_text_param.py +77 -0
  198. byteplussdkarkruntime/types/responses/response_reasoning_item.py +46 -0
  199. byteplussdkarkruntime/types/responses/response_reasoning_item_param.py +37 -0
  200. byteplussdkarkruntime/types/responses/response_reasoning_summary_part_added_event.py +42 -0
  201. byteplussdkarkruntime/types/responses/response_reasoning_summary_part_done_event.py +42 -0
  202. byteplussdkarkruntime/types/responses/response_reasoning_summary_text_delta_event.py +34 -0
  203. byteplussdkarkruntime/types/responses/response_reasoning_summary_text_done_event.py +34 -0
  204. byteplussdkarkruntime/types/responses/response_status.py +17 -0
  205. byteplussdkarkruntime/types/responses/response_stream_event.py +93 -0
  206. byteplussdkarkruntime/types/responses/response_text_config.py +28 -0
  207. byteplussdkarkruntime/types/responses/response_text_config_param.py +31 -0
  208. byteplussdkarkruntime/types/responses/response_text_delta_event.py +34 -0
  209. byteplussdkarkruntime/types/responses/response_text_done_event.py +34 -0
  210. byteplussdkarkruntime/types/responses/response_tool_usage.py +32 -0
  211. byteplussdkarkruntime/types/responses/response_usage.py +54 -0
  212. byteplussdkarkruntime/types/responses/response_web_search_call_completed_event.py +29 -0
  213. byteplussdkarkruntime/types/responses/response_web_search_call_in_progress_event.py +29 -0
  214. byteplussdkarkruntime/types/responses/response_web_search_call_searching_event.py +29 -0
  215. byteplussdkarkruntime/types/responses/response_web_search_item.py +43 -0
  216. byteplussdkarkruntime/types/responses/tool.py +25 -0
  217. byteplussdkarkruntime/types/responses/tool_choice_function.py +25 -0
  218. byteplussdkarkruntime/types/responses/tool_choice_function_param.py +25 -0
  219. byteplussdkarkruntime/types/responses/tool_choice_mcp_param.py +29 -0
  220. byteplussdkarkruntime/types/responses/tool_choice_options.py +17 -0
  221. byteplussdkarkruntime/types/responses/tool_param.py +24 -0
  222. byteplussdkarkruntime/types/responses/web_search_tool.py +49 -0
  223. byteplussdkarkruntime/types/responses/web_search_tool_param.py +46 -0
  224. byteplussdkarkruntime/types/shared/__init__.py +21 -0
  225. byteplussdkarkruntime/types/shared/reasoning.py +10 -0
  226. byteplussdkarkruntime/types/shared/reasoning_effort.py +16 -0
  227. byteplussdkarkruntime/types/shared/response_format_json_object.py +22 -0
  228. byteplussdkarkruntime/types/shared/response_format_json_schema.py +56 -0
  229. byteplussdkarkruntime/types/shared/response_format_text.py +22 -0
  230. byteplussdkarkruntime/types/shared/thinking.py +25 -0
  231. byteplussdkarkruntime/types/shared_params/__init__.py +13 -0
  232. byteplussdkarkruntime/types/shared_params/function_definition.py +34 -0
  233. byteplussdkarkruntime/types/shared_params/function_parameters.py +9 -0
  234. byteplussdkarkruntime/types/shared_params/metadata.py +20 -0
  235. byteplussdkarkruntime/types/shared_params/reasoning.py +12 -0
  236. byteplussdkarkruntime/types/shared_params/reasoning_effort.py +8 -0
  237. byteplussdkarkruntime/types/shared_params/response_format_json_object.py +22 -0
  238. byteplussdkarkruntime/types/shared_params/response_format_json_schema.py +54 -0
  239. byteplussdkarkruntime/types/shared_params/response_format_text.py +22 -0
  240. byteplussdkarkruntime/types/shared_params/thinking.py +22 -0
@@ -0,0 +1,245 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
4
+ from datetime import date, datetime
5
+ from typing_extensions import Self, Literal
6
+ import pydantic
7
+ from pydantic.fields import FieldInfo
8
+ from ._types import IncEx
9
+
10
+ _T = TypeVar("_T")
11
+ _ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
12
+ StrBytesIntFloat = Union[str, bytes, int, float]
13
+
14
+ # --------------- Pydantic v2 compatibility ---------------
15
+
16
+ # Pyright incorrectly reports some of our functions as overriding a method when they don't
17
+ # pyright: reportIncompatibleMethodOverride=false
18
+
19
+ PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
20
+
21
+ # v1 re-exports
22
+ if TYPE_CHECKING:
23
+
24
+ def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
25
+ ...
26
+
27
+ def parse_datetime(
28
+ value: Union[datetime, StrBytesIntFloat],
29
+ ) -> datetime: # noqa: ARG001
30
+ ...
31
+
32
+ def get_args(t: type[Any]) -> tuple[Any, ...]: # noqa: ARG001
33
+ ...
34
+
35
+ def is_union(tp: type[Any] | None) -> bool: # noqa: ARG001
36
+ ...
37
+
38
+ def get_origin(t: type[Any]) -> type[Any] | None: # noqa: ARG001
39
+ ...
40
+
41
+ def is_literal_type(type_: type[Any]) -> bool: # noqa: ARG001
42
+ ...
43
+
44
+ def is_typeddict(type_: type[Any]) -> bool: # noqa: ARG001
45
+ ...
46
+
47
+ else:
48
+ if PYDANTIC_V2:
49
+ from pydantic.v1.typing import (
50
+ get_args as get_args,
51
+ is_union as is_union,
52
+ get_origin as get_origin,
53
+ is_typeddict as is_typeddict,
54
+ is_literal_type as is_literal_type,
55
+ )
56
+ from pydantic.v1.datetime_parse import (
57
+ parse_date as parse_date,
58
+ parse_datetime as parse_datetime,
59
+ )
60
+ else:
61
+ from pydantic.typing import (
62
+ get_args as get_args,
63
+ is_union as is_union,
64
+ get_origin as get_origin,
65
+ is_typeddict as is_typeddict,
66
+ is_literal_type as is_literal_type,
67
+ )
68
+ from pydantic.datetime_parse import (
69
+ parse_date as parse_date,
70
+ parse_datetime as parse_datetime,
71
+ )
72
+
73
+ # refactored config
74
+ if TYPE_CHECKING:
75
+ from pydantic import ConfigDict as ConfigDict
76
+ else:
77
+ if PYDANTIC_V2:
78
+ from pydantic import ConfigDict
79
+ else:
80
+ # TODO: provide an error message here?
81
+ ConfigDict = None
82
+
83
+
84
+ # renamed methods / properties
85
+ def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
86
+ if PYDANTIC_V2:
87
+ return model.model_validate(value)
88
+ else:
89
+ return cast(
90
+ _ModelT, model.parse_obj(value)
91
+ ) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
92
+
93
+
94
+ def field_is_required(field: FieldInfo) -> bool:
95
+ if PYDANTIC_V2:
96
+ return field.is_required()
97
+ return field.required # type: ignore
98
+
99
+
100
+ def field_get_default(field: FieldInfo) -> Any:
101
+ value = field.get_default()
102
+ if PYDANTIC_V2:
103
+ from pydantic_core import PydanticUndefined
104
+
105
+ if value == PydanticUndefined:
106
+ return None
107
+ return value
108
+ return value
109
+
110
+
111
+ def field_outer_type(field: FieldInfo) -> Any:
112
+ if PYDANTIC_V2:
113
+ return field.annotation
114
+ return field.outer_type_ # type: ignore
115
+
116
+
117
+ def get_model_config(model: type[pydantic.BaseModel]) -> Any:
118
+ if PYDANTIC_V2:
119
+ return model.model_config
120
+ return model.__config__ # type: ignore
121
+
122
+
123
+ def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
124
+ if PYDANTIC_V2:
125
+ return model.model_fields
126
+ return model.__fields__ # type: ignore
127
+
128
+
129
+ def model_copy(model: _ModelT) -> _ModelT:
130
+ if PYDANTIC_V2:
131
+ return model.model_copy()
132
+ return model.copy() # type: ignore
133
+
134
+
135
+ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
136
+ if PYDANTIC_V2:
137
+ return model.model_dump_json(indent=indent)
138
+ return model.json(indent=indent) # type: ignore
139
+
140
+
141
+ def model_dump(
142
+ model: pydantic.BaseModel,
143
+ *,
144
+ exclude: IncEx | None = None,
145
+ exclude_unset: bool = False,
146
+ exclude_defaults: bool = False,
147
+ warnings: bool = True,
148
+ mode: Literal["json", "python"] = "python",
149
+ ) -> dict[str, Any]:
150
+ if PYDANTIC_V2 or hasattr(model, "model_dump"):
151
+ return model.model_dump(
152
+ mode=mode,
153
+ exclude=exclude,
154
+ exclude_unset=exclude_unset,
155
+ exclude_defaults=exclude_defaults,
156
+ # warnings are not supported in Pydantic v1
157
+ warnings=warnings if PYDANTIC_V2 else True,
158
+ )
159
+ return cast(
160
+ "dict[str, Any]",
161
+ model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
162
+ exclude=exclude,
163
+ exclude_unset=exclude_unset,
164
+ exclude_defaults=exclude_defaults,
165
+ ),
166
+ )
167
+
168
+
169
+ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
170
+ if PYDANTIC_V2:
171
+ return model.model_validate(data)
172
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
173
+
174
+
175
+ def model_parse_json(model: type[_ModelT], data: str | bytes) -> _ModelT:
176
+ if PYDANTIC_V2:
177
+ return model.model_validate_json(data)
178
+ return model.parse_raw(data) # pyright: ignore[reportDeprecated]
179
+
180
+
181
+ def model_json_schema(model: type[_ModelT]) -> dict[str, Any]:
182
+ if PYDANTIC_V2:
183
+ return model.model_json_schema()
184
+ return model.schema() # pyrigh
185
+
186
+
187
+ # generic models
188
+ if TYPE_CHECKING:
189
+
190
+ class GenericModel(pydantic.BaseModel): ...
191
+
192
+ else:
193
+ if PYDANTIC_V2:
194
+ # there no longer needs to be a distinction in v2 but
195
+ # we still have to create our own subclass to avoid
196
+ # inconsistent MRO ordering errors
197
+ class GenericModel(pydantic.BaseModel): ...
198
+
199
+ else:
200
+ import pydantic.generics
201
+
202
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
203
+
204
+
205
+ # cached properties
206
+ if TYPE_CHECKING:
207
+ cached_property = property
208
+
209
+ # we define a separate type (copied from typeshed)
210
+ # that represents that `cached_property` is `set`able
211
+ # at runtime, which differs from `@property`.
212
+ #
213
+ # this is a separate type as editors likely special case
214
+ # `@property` and we don't want to cause issues just to have
215
+ # more helpful internal types.
216
+
217
+ class typed_cached_property(Generic[_T]):
218
+ func: Callable[[Any], _T]
219
+ attrname: str | None
220
+
221
+ def __init__(self, func: Callable[[Any], _T]) -> None: ...
222
+
223
+ @overload
224
+ def __get__(self, instance: None, owner: type[Any] | None = None) -> Self: ...
225
+
226
+ @overload
227
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T: ...
228
+
229
+ def __get__(
230
+ self, instance: object, owner: type[Any] | None = None
231
+ ) -> _T | Self:
232
+ raise NotImplementedError()
233
+
234
+ def __set_name__(self, owner: type[Any], name: str) -> None: ...
235
+
236
+ # __set__ is not defined at runtime, but @cached_property is designed to be settable
237
+ def __set__(self, instance: object, value: _T) -> None: ...
238
+
239
+ else:
240
+ try:
241
+ from functools import cached_property as cached_property
242
+ except ImportError:
243
+ from cached_property import cached_property as cached_property
244
+
245
+ typed_cached_property = cached_property
@@ -0,0 +1,43 @@
1
+ # Copyright (c) [2025] [OpenAI]
2
+ # Copyright (c) [2025] [ByteDance Ltd. and/or its affiliates.]
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ #
5
+ # This file has been modified by [ByteDance Ltd. and/or its affiliates.] on 2025.7
6
+ #
7
+ # Original file was released under Apache License Version 2.0, with the full license text
8
+ # available at https://github.com/openai/openai-python/blob/main/LICENSE.
9
+ #
10
+ # This modified file is released under the same license.
11
+
12
+ import httpx
13
+
14
+ VERSION = "1.0.0"
15
+ BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3"
16
+
17
+ RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
18
+ CLIENT_REQUEST_HEADER = "X-Client-Request-Id"
19
+ SERVER_REQUEST_HEADER = "X-Request-Id"
20
+ ARK_E2E_ENCRYPTION_HEADER = "x-is-encrypted"
21
+ ARK_APIKEY_PROJECT_NAME = "X-Project-Name"
22
+
23
+ DEFAULT_TIMEOUT_SECONDS = 600.0
24
+ DEFAULT_CONNECT_TIMEOUT_SECONDS = 60.0
25
+ # default timeout is 1 minutes
26
+ DEFAULT_TIMEOUT = httpx.Timeout(
27
+ timeout=DEFAULT_TIMEOUT_SECONDS, connect=DEFAULT_CONNECT_TIMEOUT_SECONDS
28
+ )
29
+
30
+ DEFAULT_MAX_RETRIES = 2
31
+ DEFAULT_CONNECTION_LIMITS = httpx.Limits(
32
+ max_connections=1000, max_keepalive_connections=100
33
+ )
34
+
35
+ INITIAL_RETRY_DELAY = 0.5
36
+ MAX_RETRY_DELAY = 8.0
37
+
38
+ _DEFAULT_MANDATORY_REFRESH_TIMEOUT = 10 * 60 # 10 min
39
+ _DEFAULT_ADVISORY_REFRESH_TIMEOUT = 30 * 60 # 30 min
40
+ _DEFAULT_STS_TIMEOUT = 7 * 24 * 60 * 60 # 7 days
41
+
42
+ _DEFAULT_RESOURCE_TYPE = "endpoint"
43
+ _PRESETENDPOINT_RESOURCE_TYPE = "presetendpoint"
@@ -0,0 +1,202 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Optional
6
+ from typing_extensions import Literal
7
+ import httpx
8
+
9
+ if TYPE_CHECKING:
10
+ from .types.chat import ChatCompletion
11
+
12
+
13
+ __all__ = [
14
+ "ArkBadRequestError",
15
+ "ArkAuthenticationError",
16
+ "ArkPermissionDeniedError",
17
+ "ArkNotFoundError",
18
+ "ArkConflictError",
19
+ "ArkUnprocessableEntityError",
20
+ "ArkRateLimitError",
21
+ "ArkInternalServerError",
22
+ ]
23
+
24
+
25
+ class ArkError(Exception):
26
+ pass
27
+
28
+
29
+ class ArkAPIError(ArkError):
30
+ message: str
31
+ request: Optional[httpx.Request] = None
32
+ body: Optional[object] = None
33
+ request_id: Optional[str] = None
34
+ """The API response body.
35
+
36
+ If the API responded with a valid JSON structure then this property will be the
37
+ decoded result.
38
+
39
+ If it isn't a valid JSON structure then this will be the raw response.
40
+
41
+ If there was no response associated with this error then it will be `None`.
42
+ """
43
+
44
+ code: Optional[str] = None
45
+ param: Optional[str] = None
46
+ type: Optional[str]
47
+
48
+ def __init__(
49
+ self,
50
+ message: str,
51
+ request: Optional[httpx.Request] = None,
52
+ *,
53
+ body: Optional[object] = None,
54
+ request_id: Optional[str] = None,
55
+ ) -> None:
56
+ super().__init__(message)
57
+ self.request = request
58
+ self.message = message
59
+ self.body = body
60
+ self.request_id = request_id
61
+
62
+ if isinstance(body, dict):
63
+ self.code = body.get("code")
64
+ self.param = body.get("param")
65
+ self.type = body.get("type")
66
+ else:
67
+ self.code = None
68
+ self.param = None
69
+ self.type = None
70
+
71
+ def __str__(self):
72
+ return f"{self.message}, request_id: {self.request_id}"
73
+
74
+
75
+ class ArkAPIResponseValidationError(ArkAPIError):
76
+ response: httpx.Response
77
+ status_code: int
78
+
79
+ def __init__(
80
+ self,
81
+ response: httpx.Response,
82
+ body: object | None,
83
+ *,
84
+ message: str | None = None,
85
+ request_id: str,
86
+ ) -> None:
87
+ super().__init__(
88
+ message or "Data returned by API invalid for expected schema.",
89
+ response.request,
90
+ body=body,
91
+ )
92
+ self.response = response
93
+ self.status_code = response.status_code
94
+ self.request_id = request_id
95
+
96
+
97
+ class ArkAPIStatusError(ArkAPIError):
98
+ """Raised when an API response has a status code of 4xx or 5xx."""
99
+
100
+ response: httpx.Response
101
+ status_code: int
102
+
103
+ def __init__(
104
+ self,
105
+ message: str,
106
+ *,
107
+ response: httpx.Response,
108
+ body: object | None,
109
+ request_id: str,
110
+ ) -> None:
111
+ super().__init__(message, response.request, body=body, request_id=request_id)
112
+ self.response = response
113
+ self.status_code = response.status_code
114
+ self.request_id = request_id
115
+
116
+
117
+ class ArkAPIConnectionError(ArkAPIError):
118
+ def __init__(
119
+ self,
120
+ *,
121
+ message: str = "Connection error.",
122
+ request: httpx.Request,
123
+ request_id: str,
124
+ ) -> None:
125
+ super().__init__(message, request, body=None, request_id=request_id)
126
+
127
+
128
+ class ArkAPITimeoutError(ArkAPIConnectionError):
129
+ def __init__(self, request: httpx.Request, request_id: str) -> None:
130
+ super().__init__(
131
+ message="Request timed out.", request=request, request_id=request_id
132
+ )
133
+
134
+
135
+ class ArkBadRequestError(ArkAPIStatusError):
136
+ status_code: Literal[400] = (
137
+ 400 # pyright: ignore[reportIncompatibleVariableOverride]
138
+ )
139
+
140
+
141
+ class ArkAuthenticationError(ArkAPIStatusError):
142
+ status_code: Literal[401] = (
143
+ 401 # pyright: ignore[reportIncompatibleVariableOverride]
144
+ )
145
+
146
+
147
+ class ArkPermissionDeniedError(ArkAPIStatusError):
148
+ status_code: Literal[403] = (
149
+ 403 # pyright: ignore[reportIncompatibleVariableOverride]
150
+ )
151
+
152
+
153
+ class ArkNotFoundError(ArkAPIStatusError):
154
+ status_code: Literal[404] = (
155
+ 404 # pyright: ignore[reportIncompatibleVariableOverride]
156
+ )
157
+
158
+
159
+ class ArkConflictError(ArkAPIStatusError):
160
+ status_code: Literal[409] = (
161
+ 409 # pyright: ignore[reportIncompatibleVariableOverride]
162
+ )
163
+
164
+
165
+ class ArkUnprocessableEntityError(ArkAPIStatusError):
166
+ status_code: Literal[422] = (
167
+ 422 # pyright: ignore[reportIncompatibleVariableOverride]
168
+ )
169
+
170
+
171
+ class ArkRateLimitError(ArkAPIStatusError):
172
+ status_code: Literal[429] = (
173
+ 429 # pyright: ignore[reportIncompatibleVariableOverride]
174
+ )
175
+
176
+
177
+ class ArkInternalServerError(ArkAPIStatusError):
178
+ pass
179
+
180
+
181
+ class ArkLengthFinishReasonError(ArkError):
182
+ completion: ChatCompletion
183
+ """The completion that caused this error.
184
+
185
+ Note: this will *not* be a complete `ChatCompletion` object when streaming as `usage`
186
+ will not be included.
187
+ """
188
+
189
+ def __init__(self, *, completion: ChatCompletion) -> None:
190
+ msg = "Could not parse response content as the length limit was reached"
191
+ if completion.usage:
192
+ msg += f" - {completion.usage}"
193
+
194
+ super().__init__(msg)
195
+ self.completion = completion
196
+
197
+
198
+ class ArkContentFilterFinishReasonError(ArkError):
199
+ def __init__(self) -> None:
200
+ super().__init__(
201
+ "Could not parse response content as the request was rejected by the content filter",
202
+ )
@@ -0,0 +1,149 @@
1
+ # Copyright (c) [2025] [OpenAI]
2
+ # Copyright (c) [2025] [ByteDance Ltd. and/or its affiliates.]
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ #
5
+ # This file has been modified by [ByteDance Ltd. and/or its affiliates.] on 2025.7
6
+ #
7
+ # Original file was released under Apache License Version 2.0, with the full license text
8
+ # available at https://github.com/openai/openai-python/blob/main/LICENSE.
9
+ #
10
+ # This modified file is released under the same license.
11
+
12
+ from __future__ import annotations
13
+
14
+ import io
15
+ import os
16
+ import pathlib
17
+ from typing import overload
18
+ from typing_extensions import TypeGuard
19
+
20
+ import anyio
21
+
22
+ from ._types import (
23
+ FileTypes,
24
+ FileContent,
25
+ RequestFiles,
26
+ HttpxFileTypes,
27
+ Base64FileInput,
28
+ HttpxFileContent,
29
+ HttpxRequestFiles,
30
+ )
31
+ from ._utils import is_tuple_t, is_mapping_t, is_sequence_t
32
+
33
+
34
+ def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
35
+ return isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)
36
+
37
+
38
+ def is_file_content(obj: object) -> TypeGuard[FileContent]:
39
+ return (
40
+ isinstance(obj, bytes)
41
+ or isinstance(obj, tuple)
42
+ or isinstance(obj, io.IOBase)
43
+ or isinstance(obj, os.PathLike)
44
+ )
45
+
46
+
47
+ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
48
+ if not is_file_content(obj):
49
+ prefix = (
50
+ f"Expected entry at `{key}`"
51
+ if key is not None
52
+ else f"Expected file input `{obj!r}`"
53
+ )
54
+ raise RuntimeError(
55
+ f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. "
56
+ ) from None
57
+
58
+
59
+ @overload
60
+ def to_httpx_files(files: None) -> None: ...
61
+
62
+
63
+ @overload
64
+ def to_httpx_files(files: RequestFiles) -> HttpxRequestFiles: ...
65
+
66
+
67
+ def to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles | None:
68
+ if files is None:
69
+ return None
70
+
71
+ if is_mapping_t(files):
72
+ files = {key: _transform_file(file) for key, file in files.items()}
73
+ elif is_sequence_t(files):
74
+ files = [(key, _transform_file(file)) for key, file in files]
75
+ else:
76
+ raise TypeError(
77
+ f"Unexpected file type input {type(files)}, expected mapping or sequence"
78
+ )
79
+
80
+ return files
81
+
82
+
83
+ def _transform_file(file: FileTypes) -> HttpxFileTypes:
84
+ if is_file_content(file):
85
+ if isinstance(file, os.PathLike):
86
+ path = pathlib.Path(file)
87
+ return (path.name, path.read_bytes())
88
+
89
+ return file
90
+
91
+ if is_tuple_t(file):
92
+ return (file[0], _read_file_content(file[1]), *file[2:])
93
+
94
+ raise TypeError(
95
+ "Expected file types input to be a FileContent type or to be a tuple"
96
+ )
97
+
98
+
99
+ def _read_file_content(file: FileContent) -> HttpxFileContent:
100
+ if isinstance(file, os.PathLike):
101
+ return pathlib.Path(file).read_bytes()
102
+ return file
103
+
104
+
105
+ @overload
106
+ async def async_to_httpx_files(files: None) -> None: ...
107
+
108
+
109
+ @overload
110
+ async def async_to_httpx_files(files: RequestFiles) -> HttpxRequestFiles: ...
111
+
112
+
113
+ async def async_to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles | None:
114
+ if files is None:
115
+ return None
116
+
117
+ if is_mapping_t(files):
118
+ files = {key: await _async_transform_file(file) for key, file in files.items()}
119
+ elif is_sequence_t(files):
120
+ files = [(key, await _async_transform_file(file)) for key, file in files]
121
+ else:
122
+ raise TypeError(
123
+ "Unexpected file type input {type(files)}, expected mapping or sequence"
124
+ )
125
+
126
+ return files
127
+
128
+
129
+ async def _async_transform_file(file: FileTypes) -> HttpxFileTypes:
130
+ if is_file_content(file):
131
+ if isinstance(file, os.PathLike):
132
+ path = anyio.Path(file)
133
+ return (path.name, await path.read_bytes())
134
+
135
+ return file
136
+
137
+ if is_tuple_t(file):
138
+ return (file[0], await _async_read_file_content(file[1]), *file[2:])
139
+
140
+ raise TypeError(
141
+ "Expected file types input to be a FileContent type or to be a tuple"
142
+ )
143
+
144
+
145
+ async def _async_read_file_content(file: FileContent) -> HttpxFileContent:
146
+ if isinstance(file, os.PathLike):
147
+ return await anyio.Path(file).read_bytes()
148
+
149
+ return file