Debian Codegraph @

src/anthropic/resources/skills/versions.py

raw
1 from __future__ import annotations
2
3 from typing import Mapping, Optional, cast
4
5 import httpx2
6
7 from ..._files import deepcopy_with_paths
8 from ..._types import (
9 Body,
10 Omit,
11 Query,
12 Headers,
13 NotGiven,
14 FileTypes,
15 SequenceNotStr,
16 omit,
17 not_given,
18 )
19 from ..._utils import extract_files, path_template, strip_not_given
20 from ..._compat import cached_property
21 from ..._resource import SyncAPIResource, AsyncAPIResource
22 from ..._response import (
23 to_raw_response_wrapper,
24 to_streamed_response_wrapper,
25 async_to_raw_response_wrapper,
26 async_to_streamed_response_wrapper,
27 )
28 from ...pagination import SyncPageCursor, AsyncPageCursor
29 from ..._base_client import AsyncPaginator, make_request_options
30 from ...types.skills.skill_version import SkillVersion
31 from ...types.skills.deleted_skill_version import DeletedSkillVersion
32
33 __all__ = ["Versions", "AsyncVersions"]
34
35
36 class Versions(SyncAPIResource):
37 @cached_property
38 def with_raw_response(self) -> VersionsWithRawResponse:
39 """
40 This property can be used as a prefix for any HTTP method call to return
41 the raw response object instead of the parsed content.
42
43 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
44 """
45 return VersionsWithRawResponse(self)
46
47 @cached_property
48 def with_streaming_response(self) -> VersionsWithStreamingResponse:
49 """
50 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
51
52 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
53 """
54 return VersionsWithStreamingResponse(self)
55
56 def create(
57 self,
58 skill_id: str,
59 *,
60 files: SequenceNotStr[FileTypes],
61 workspace_id: str | Omit = omit,
62 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
63 # The extra values given here take precedence over values defined on the client or passed to this method.
64 extra_headers: Headers | None = None,
65 extra_query: Query | None = None,
66 extra_body: Body | None = None,
67 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
68 ) -> SkillVersion:
69 """
70 Create Skill Version
71
72 Args:
73 skill_id: Unique identifier for the skill.
74
75 The format and length of IDs may change over time.
76
77 files: Files to upload for the skill.
78
79 All files must be in the same top-level directory and must include a SKILL.md
80 file at the root of that directory.
81
82 workspace_id: Optional header to select the Workspace for this request. The value is a
83 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
84
85 Only needed for credentials that can act on more than one Workspace. A
86 credential that belongs to a specific Workspace may omit it; if sent, it must
87 match that Workspace.
88
89 extra_headers: Send extra headers
90
91 extra_query: Add additional query parameters to the request
92
93 extra_body: Add additional JSON properties to the request
94
95 timeout: Override the client-level default timeout for this request, in seconds
96 """
97 if not skill_id:
98 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
99 extra_headers = {**strip_not_given({"anthropic-workspace-id": workspace_id}), **(extra_headers or {})}
100 body = deepcopy_with_paths({"files": files}, [["files", "<array>"]])
101 extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
102 # It should be noted that the actual Content-Type header that will be
103 # sent to the server will contain a `boundary` parameter, e.g.
104 # multipart/form-data; boundary=---abc--
105 extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
106 return self._post(
107 path_template("/v1/skills/{skill_id}/versions", skill_id=skill_id),
108 body=body,
109 files=extracted_files,
110 options=make_request_options(
111 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
112 ),
113 cast_to=SkillVersion,
114 )
115
116 def retrieve(
117 self,
118 version: str,
119 *,
120 skill_id: str,
121 workspace_id: str | Omit = omit,
122 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
123 # The extra values given here take precedence over values defined on the client or passed to this method.
124 extra_headers: Headers | None = None,
125 extra_query: Query | None = None,
126 extra_body: Body | None = None,
127 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
128 ) -> SkillVersion:
129 """
130 Get Skill Version
131
132 Args:
133 skill_id: Unique identifier for the skill.
134
135 The format and length of IDs may change over time.
136
137 version: Identifies the skill version: a version ID, or the literal `latest` for the
138 skill's most recent version.
139
140 Requests carrying the `skills-2025-10-02` beta header address versions by their
141 Unix epoch timestamp instead (e.g., "1759178010641129").
142
143 workspace_id: Optional header to select the Workspace for this request. The value is a
144 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
145
146 Only needed for credentials that can act on more than one Workspace. A
147 credential that belongs to a specific Workspace may omit it; if sent, it must
148 match that Workspace.
149
150 extra_headers: Send extra headers
151
152 extra_query: Add additional query parameters to the request
153
154 extra_body: Add additional JSON properties to the request
155
156 timeout: Override the client-level default timeout for this request, in seconds
157 """
158 if not skill_id:
159 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
160 if not version:
161 raise ValueError(f"Expected a non-empty value for `version` but received {version!r}")
162 extra_headers = {**strip_not_given({"anthropic-workspace-id": workspace_id}), **(extra_headers or {})}
163 return self._get(
164 path_template("/v1/skills/{skill_id}/versions/{version}", skill_id=skill_id, version=version),
165 options=make_request_options(
166 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
167 ),
168 cast_to=SkillVersion,
169 )
170
171 def list(
172 self,
173 skill_id: str,
174 *,
175 limit: Optional[int] | Omit = omit,
176 page: Optional[str] | Omit = omit,
177 workspace_id: str | Omit = omit,
178 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
179 # The extra values given here take precedence over values defined on the client or passed to this method.
180 extra_headers: Headers | None = None,
181 extra_query: Query | None = None,
182 extra_body: Body | None = None,
183 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
184 ) -> SyncPageCursor[SkillVersion]:
185 """
186 List Skill Versions
187
188 Args:
189 skill_id: Unique identifier for the skill.
190
191 The format and length of IDs may change over time.
192
193 limit: Number of results to return per page.
194
195 Ranges from `1` to `1000`. Defaults to `20`.
196
197 page: Optionally set to the `next_page` token from the previous response.
198
199 workspace_id: Optional header to select the Workspace for this request. The value is a
200 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
201
202 Only needed for credentials that can act on more than one Workspace. A
203 credential that belongs to a specific Workspace may omit it; if sent, it must
204 match that Workspace.
205
206 extra_headers: Send extra headers
207
208 extra_query: Add additional query parameters to the request
209
210 extra_body: Add additional JSON properties to the request
211
212 timeout: Override the client-level default timeout for this request, in seconds
213 """
214 if not skill_id:
215 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
216 extra_headers = {**strip_not_given({"anthropic-workspace-id": workspace_id}), **(extra_headers or {})}
217 return self._get_api_list(
218 path_template("/v1/skills/{skill_id}/versions", skill_id=skill_id),
219 page=SyncPageCursor[SkillVersion],
220 options=make_request_options(
221 extra_headers=extra_headers,
222 extra_query=extra_query,
223 extra_body=extra_body,
224 timeout=timeout,
225 query={
226 "limit": limit,
227 "page": page,
228 },
229 ),
230 model=SkillVersion,
231 )
232
233 def delete(
234 self,
235 version: str,
236 *,
237 skill_id: str,
238 workspace_id: str | Omit = omit,
239 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
240 # The extra values given here take precedence over values defined on the client or passed to this method.
241 extra_headers: Headers | None = None,
242 extra_query: Query | None = None,
243 extra_body: Body | None = None,
244 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
245 ) -> DeletedSkillVersion:
246 """
247 Delete Skill Version
248
249 Args:
250 skill_id: Unique identifier for the skill.
251
252 The format and length of IDs may change over time.
253
254 version: Identifies the skill version by its version ID.
255
256 Requests carrying the `skills-2025-10-02` beta header address versions by their
257 Unix epoch timestamp instead (e.g., "1759178010641129").
258
259 workspace_id: Optional header to select the Workspace for this request. The value is a
260 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
261
262 Only needed for credentials that can act on more than one Workspace. A
263 credential that belongs to a specific Workspace may omit it; if sent, it must
264 match that Workspace.
265
266 extra_headers: Send extra headers
267
268 extra_query: Add additional query parameters to the request
269
270 extra_body: Add additional JSON properties to the request
271
272 timeout: Override the client-level default timeout for this request, in seconds
273 """
274 if not skill_id:
275 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
276 if not version:
277 raise ValueError(f"Expected a non-empty value for `version` but received {version!r}")
278 extra_headers = {**strip_not_given({"anthropic-workspace-id": workspace_id}), **(extra_headers or {})}
279 return self._delete(
280 path_template("/v1/skills/{skill_id}/versions/{version}", skill_id=skill_id, version=version),
281 options=make_request_options(
282 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
283 ),
284 cast_to=DeletedSkillVersion,
285 )
286
287
288 class AsyncVersions(AsyncAPIResource):
289 @cached_property
290 def with_raw_response(self) -> AsyncVersionsWithRawResponse:
291 """
292 This property can be used as a prefix for any HTTP method call to return
293 the raw response object instead of the parsed content.
294
295 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
296 """
297 return AsyncVersionsWithRawResponse(self)
298
299 @cached_property
300 def with_streaming_response(self) -> AsyncVersionsWithStreamingResponse:
301 """
302 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
303
304 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
305 """
306 return AsyncVersionsWithStreamingResponse(self)
307
308 async def create(
309 self,
310 skill_id: str,
311 *,
312 files: SequenceNotStr[FileTypes],
313 workspace_id: str | Omit = omit,
314 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
315 # The extra values given here take precedence over values defined on the client or passed to this method.
316 extra_headers: Headers | None = None,
317 extra_query: Query | None = None,
318 extra_body: Body | None = None,
319 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
320 ) -> SkillVersion:
321 """
322 Create Skill Version
323
324 Args:
325 skill_id: Unique identifier for the skill.
326
327 The format and length of IDs may change over time.
328
329 files: Files to upload for the skill.
330
331 All files must be in the same top-level directory and must include a SKILL.md
332 file at the root of that directory.
333
334 workspace_id: Optional header to select the Workspace for this request. The value is a
335 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
336
337 Only needed for credentials that can act on more than one Workspace. A
338 credential that belongs to a specific Workspace may omit it; if sent, it must
339 match that Workspace.
340
341 extra_headers: Send extra headers
342
343 extra_query: Add additional query parameters to the request
344
345 extra_body: Add additional JSON properties to the request
346
347 timeout: Override the client-level default timeout for this request, in seconds
348 """
349 if not skill_id:
350 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
351 extra_headers = {**strip_not_given({"anthropic-workspace-id": workspace_id}), **(extra_headers or {})}
352 body = deepcopy_with_paths({"files": files}, [["files", "<array>"]])
353 extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
354 # It should be noted that the actual Content-Type header that will be
355 # sent to the server will contain a `boundary` parameter, e.g.
356 # multipart/form-data; boundary=---abc--
357 extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
358 return await self._post(
359 path_template("/v1/skills/{skill_id}/versions", skill_id=skill_id),
360 body=body,
361 files=extracted_files,
362 options=make_request_options(
363 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
364 ),
365 cast_to=SkillVersion,
366 )
367
368 async def retrieve(
369 self,
370 version: str,
371 *,
372 skill_id: str,
373 workspace_id: str | Omit = omit,
374 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
375 # The extra values given here take precedence over values defined on the client or passed to this method.
376 extra_headers: Headers | None = None,
377 extra_query: Query | None = None,
378 extra_body: Body | None = None,
379 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
380 ) -> SkillVersion:
381 """
382 Get Skill Version
383
384 Args:
385 skill_id: Unique identifier for the skill.
386
387 The format and length of IDs may change over time.
388
389 version: Identifies the skill version: a version ID, or the literal `latest` for the
390 skill's most recent version.
391
392 Requests carrying the `skills-2025-10-02` beta header address versions by their
393 Unix epoch timestamp instead (e.g., "1759178010641129").
394
395 workspace_id: Optional header to select the Workspace for this request. The value is a
396 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
397
398 Only needed for credentials that can act on more than one Workspace. A
399 credential that belongs to a specific Workspace may omit it; if sent, it must
400 match that Workspace.
401
402 extra_headers: Send extra headers
403
404 extra_query: Add additional query parameters to the request
405
406 extra_body: Add additional JSON properties to the request
407
408 timeout: Override the client-level default timeout for this request, in seconds
409 """
410 if not skill_id:
411 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
412 if not version:
413 raise ValueError(f"Expected a non-empty value for `version` but received {version!r}")
414 extra_headers = {**strip_not_given({"anthropic-workspace-id": workspace_id}), **(extra_headers or {})}
415 return await self._get(
416 path_template("/v1/skills/{skill_id}/versions/{version}", skill_id=skill_id, version=version),
417 options=make_request_options(
418 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
419 ),
420 cast_to=SkillVersion,
421 )
422
423 def list(
424 self,
425 skill_id: str,
426 *,
427 limit: Optional[int] | Omit = omit,
428 page: Optional[str] | Omit = omit,
429 workspace_id: str | Omit = omit,
430 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
431 # The extra values given here take precedence over values defined on the client or passed to this method.
432 extra_headers: Headers | None = None,
433 extra_query: Query | None = None,
434 extra_body: Body | None = None,
435 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
436 ) -> AsyncPaginator[SkillVersion, AsyncPageCursor[SkillVersion]]:
437 """
438 List Skill Versions
439
440 Args:
441 skill_id: Unique identifier for the skill.
442
443 The format and length of IDs may change over time.
444
445 limit: Number of results to return per page.
446
447 Ranges from `1` to `1000`. Defaults to `20`.
448
449 page: Optionally set to the `next_page` token from the previous response.
450
451 workspace_id: Optional header to select the Workspace for this request. The value is a
452 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
453
454 Only needed for credentials that can act on more than one Workspace. A
455 credential that belongs to a specific Workspace may omit it; if sent, it must
456 match that Workspace.
457
458 extra_headers: Send extra headers
459
460 extra_query: Add additional query parameters to the request
461
462 extra_body: Add additional JSON properties to the request
463
464 timeout: Override the client-level default timeout for this request, in seconds
465 """
466 if not skill_id:
467 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
468 extra_headers = {**strip_not_given({"anthropic-workspace-id": workspace_id}), **(extra_headers or {})}
469 return self._get_api_list(
470 path_template("/v1/skills/{skill_id}/versions", skill_id=skill_id),
471 page=AsyncPageCursor[SkillVersion],
472 options=make_request_options(
473 extra_headers=extra_headers,
474 extra_query=extra_query,
475 extra_body=extra_body,
476 timeout=timeout,
477 query={
478 "limit": limit,
479 "page": page,
480 },
481 ),
482 model=SkillVersion,
483 )
484
485 async def delete(
486 self,
487 version: str,
488 *,
489 skill_id: str,
490 workspace_id: str | Omit = omit,
491 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
492 # The extra values given here take precedence over values defined on the client or passed to this method.
493 extra_headers: Headers | None = None,
494 extra_query: Query | None = None,
495 extra_body: Body | None = None,
496 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
497 ) -> DeletedSkillVersion:
498 """
499 Delete Skill Version
500
501 Args:
502 skill_id: Unique identifier for the skill.
503
504 The format and length of IDs may change over time.
505
506 version: Identifies the skill version by its version ID.
507
508 Requests carrying the `skills-2025-10-02` beta header address versions by their
509 Unix epoch timestamp instead (e.g., "1759178010641129").
510
511 workspace_id: Optional header to select the Workspace for this request. The value is a
512 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
513
514 Only needed for credentials that can act on more than one Workspace. A
515 credential that belongs to a specific Workspace may omit it; if sent, it must
516 match that Workspace.
517
518 extra_headers: Send extra headers
519
520 extra_query: Add additional query parameters to the request
521
522 extra_body: Add additional JSON properties to the request
523
524 timeout: Override the client-level default timeout for this request, in seconds
525 """
526 if not skill_id:
527 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
528 if not version:
529 raise ValueError(f"Expected a non-empty value for `version` but received {version!r}")
530 extra_headers = {**strip_not_given({"anthropic-workspace-id": workspace_id}), **(extra_headers or {})}
531 return await self._delete(
532 path_template("/v1/skills/{skill_id}/versions/{version}", skill_id=skill_id, version=version),
533 options=make_request_options(
534 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
535 ),
536 cast_to=DeletedSkillVersion,
537 )
538
539
540 class VersionsWithRawResponse:
541 def __init__(self, versions: Versions) -> None:
542 self._versions = versions
543
544 self.create = to_raw_response_wrapper(
545 versions.create,
546 )
547 self.retrieve = to_raw_response_wrapper(
548 versions.retrieve,
549 )
550 self.list = to_raw_response_wrapper(
551 versions.list,
552 )
553 self.delete = to_raw_response_wrapper(
554 versions.delete,
555 )
556
557
558 class AsyncVersionsWithRawResponse:
559 def __init__(self, versions: AsyncVersions) -> None:
560 self._versions = versions
561
562 self.create = async_to_raw_response_wrapper(
563 versions.create,
564 )
565 self.retrieve = async_to_raw_response_wrapper(
566 versions.retrieve,
567 )
568 self.list = async_to_raw_response_wrapper(
569 versions.list,
570 )
571 self.delete = async_to_raw_response_wrapper(
572 versions.delete,
573 )
574
575
576 class VersionsWithStreamingResponse:
577 def __init__(self, versions: Versions) -> None:
578 self._versions = versions
579
580 self.create = to_streamed_response_wrapper(
581 versions.create,
582 )
583 self.retrieve = to_streamed_response_wrapper(
584 versions.retrieve,
585 )
586 self.list = to_streamed_response_wrapper(
587 versions.list,
588 )
589 self.delete = to_streamed_response_wrapper(
590 versions.delete,
591 )
592
593
594 class AsyncVersionsWithStreamingResponse:
595 def __init__(self, versions: AsyncVersions) -> None:
596 self._versions = versions
597
598 self.create = async_to_streamed_response_wrapper(
599 versions.create,
600 )
601 self.retrieve = async_to_streamed_response_wrapper(
602 versions.retrieve,
603 )
604 self.list = async_to_streamed_response_wrapper(
605 versions.list,
606 )
607 self.delete = async_to_streamed_response_wrapper(
608 versions.delete,
609 )