22Tokens resource for managing watermark tokens
33"""
44
5- from typing import List , Optional , Literal
5+ from typing import Any , List , Literal , Optional
66from .base import BaseResource
7- from ..models .token import Token , TokenCreateParams , TokenUpdateParams
7+ from ..models .token import AiAuthTag , UNSET , Token , TokenCreateParams , TokenUpdateParams
88from ..exceptions import raise_for_error
99
1010
1111class TokensResource (BaseResource ):
1212 """Resource for managing watermark tokens"""
1313
14+ def list_ai_auth_tags (self ) -> List [AiAuthTag ]:
15+ """List reusable AI authorization tags for the current account."""
16+ response = self ._get ("/tokens/ai-auth-tags" )
17+ data = response .json ()
18+ raise_for_error (data , response .status_code )
19+
20+ tags_data = data if isinstance (data , list ) else data .get ("data" , {}).get ("tags" , [])
21+ return [AiAuthTag .from_dict (tag ) for tag in tags_data ]
22+
23+ def create_ai_auth_tag (self , tag : str ) -> AiAuthTag :
24+ """Create or retrieve a reusable AI authorization tag."""
25+ normalized_tag = tag .strip ()
26+ if not normalized_tag :
27+ raise ValueError ("tag must not be empty" )
28+
29+ response = self ._post ("/tokens/ai-auth-tags" , json = {"tag" : normalized_tag })
30+ data = response .json ()
31+ raise_for_error (data , response .status_code )
32+
33+ tag_data = data if isinstance (data , dict ) and "id" in data else data .get ("data" , {})
34+ return AiAuthTag .from_dict (tag_data )
35+
1436 def list (self ) -> List [Token ]:
1537 """
1638 List all tokens for the current user.
@@ -58,6 +80,11 @@ def create(
5880 name : str ,
5981 token_type : Literal ["standard" , "pro" ] = "standard" ,
6082 public_key : Optional [int ] = None ,
83+ ai_auth_enabled : bool = False ,
84+ ai_auth_access_type : Optional [Literal ["direct_use" , "premium_track" ]] = None ,
85+ ai_auth_price : Optional [float ] = None ,
86+ ai_auth_other_instructions : Optional [str ] = None ,
87+ ai_auth_tags : Optional [List [str ]] = None ,
6188 ) -> Token :
6289 """
6390 Create a new watermark token.
@@ -67,6 +94,11 @@ def create(
6794 token_type: "standard" (default) or "pro"
6895 public_key: Verification key when your token workflow requires one.
6996 Defaults to 258 for pro tokens if not provided.
97+ ai_auth_enabled: Whether AI authorization is enabled
98+ ai_auth_access_type: "direct_use" or "premium_track" (optional)
99+ ai_auth_price: AI authorization price; must be at least 1 when set
100+ ai_auth_other_instructions: Additional AI authorization instructions
101+ ai_auth_tags: Searchable AI authorization tags
70102
71103 Returns:
72104 Newly created Token object
@@ -95,6 +127,11 @@ def create(
95127 name = name ,
96128 token_type = token_type ,
97129 public_key = public_key ,
130+ ai_auth_enabled = ai_auth_enabled ,
131+ ai_auth_access_type = ai_auth_access_type ,
132+ ai_auth_price = ai_auth_price ,
133+ ai_auth_other_instructions = ai_auth_other_instructions ,
134+ ai_auth_tags = ai_auth_tags ,
98135 )
99136
100137 response = self ._post ("/tokens/" , json = params .to_dict ())
@@ -111,7 +148,13 @@ def update(
111148 token_id : str ,
112149 name : Optional [str ] = None ,
113150 public_key : Optional [int ] = None ,
151+ token_type : Optional [Literal ["standard" , "pro" , "enterprise" ]] = None ,
114152 enterprise_verification : Optional [bool ] = None ,
153+ ai_auth_enabled : Optional [bool ] = None ,
154+ ai_auth_access_type : Optional [Literal ["direct_use" , "premium_track" ]] = None ,
155+ ai_auth_price : Any = UNSET ,
156+ ai_auth_other_instructions : Optional [str ] = None ,
157+ ai_auth_tags : Optional [List [str ]] = None ,
115158 ) -> Token :
116159 """
117160 Update an existing token.
@@ -120,15 +163,27 @@ def update(
120163 token_id: The token UUID
121164 name: New name (optional)
122165 public_key: New verification key when your token workflow supports it (optional)
166+ token_type: New token type. The API permits upgrades but rejects downgrades.
123167 enterprise_verification: Enterprise-only verification setting for eligible accounts (optional)
168+ ai_auth_enabled: Whether AI authorization is enabled
169+ ai_auth_access_type: "direct_use" or "premium_track" (optional)
170+ ai_auth_price: AI authorization price, or None to clear it
171+ ai_auth_other_instructions: Additional AI authorization instructions
172+ ai_auth_tags: Replacement list of AI authorization tags
124173
125174 Returns:
126175 Updated Token object
127176 """
128177 params = TokenUpdateParams (
129178 name = name ,
130179 public_key = public_key ,
180+ token_type = token_type ,
131181 enterprise_verification = enterprise_verification ,
182+ ai_auth_enabled = ai_auth_enabled ,
183+ ai_auth_access_type = ai_auth_access_type ,
184+ ai_auth_price = ai_auth_price ,
185+ ai_auth_other_instructions = ai_auth_other_instructions ,
186+ ai_auth_tags = ai_auth_tags ,
132187 )
133188
134189 update_data = params .to_dict ()
0 commit comments