payi 0.1.0a107__py3-none-any.whl → 0.1.0a137__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 (83) hide show
  1. payi/__init__.py +3 -1
  2. payi/_base_client.py +12 -12
  3. payi/_client.py +8 -8
  4. payi/_compat.py +48 -48
  5. payi/_models.py +87 -59
  6. payi/_qs.py +7 -7
  7. payi/_streaming.py +4 -6
  8. payi/_types.py +53 -12
  9. payi/_utils/__init__.py +9 -2
  10. payi/_utils/_compat.py +45 -0
  11. payi/_utils/_datetime_parse.py +136 -0
  12. payi/_utils/_sync.py +3 -31
  13. payi/_utils/_transform.py +13 -3
  14. payi/_utils/_typing.py +6 -1
  15. payi/_utils/_utils.py +5 -6
  16. payi/_version.py +1 -1
  17. payi/lib/AnthropicInstrumentor.py +83 -57
  18. payi/lib/BedrockInstrumentor.py +292 -57
  19. payi/lib/GoogleGenAiInstrumentor.py +18 -31
  20. payi/lib/OpenAIInstrumentor.py +56 -72
  21. payi/lib/ProviderRequest.py +216 -0
  22. payi/lib/StreamWrappers.py +379 -0
  23. payi/lib/VertexInstrumentor.py +18 -37
  24. payi/lib/VertexRequest.py +16 -2
  25. payi/lib/data/cohere_embed_english_v3.json +30706 -0
  26. payi/lib/helpers.py +62 -5
  27. payi/lib/instrument.py +433 -659
  28. payi/resources/categories/__init__.py +0 -14
  29. payi/resources/categories/categories.py +25 -53
  30. payi/resources/categories/resources.py +27 -23
  31. payi/resources/ingest.py +126 -132
  32. payi/resources/limits/__init__.py +14 -14
  33. payi/resources/limits/limits.py +58 -58
  34. payi/resources/limits/properties.py +171 -0
  35. payi/resources/requests/request_id/properties.py +8 -8
  36. payi/resources/requests/request_id/result.py +3 -3
  37. payi/resources/requests/response_id/properties.py +8 -8
  38. payi/resources/requests/response_id/result.py +3 -3
  39. payi/resources/use_cases/definitions/definitions.py +27 -27
  40. payi/resources/use_cases/definitions/kpis.py +23 -23
  41. payi/resources/use_cases/definitions/limit_config.py +14 -14
  42. payi/resources/use_cases/definitions/version.py +3 -3
  43. payi/resources/use_cases/kpis.py +15 -15
  44. payi/resources/use_cases/properties.py +6 -6
  45. payi/resources/use_cases/use_cases.py +7 -7
  46. payi/types/__init__.py +2 -0
  47. payi/types/bulk_ingest_response.py +3 -20
  48. payi/types/categories/__init__.py +0 -1
  49. payi/types/categories/resource_list_params.py +5 -1
  50. payi/types/category_list_resources_params.py +5 -1
  51. payi/types/category_resource_response.py +31 -1
  52. payi/types/ingest_event_param.py +7 -6
  53. payi/types/ingest_units_params.py +5 -4
  54. payi/types/limit_create_params.py +3 -3
  55. payi/types/limit_list_response.py +1 -3
  56. payi/types/limit_response.py +1 -3
  57. payi/types/limits/__init__.py +2 -9
  58. payi/types/limits/{tag_remove_params.py → property_update_params.py} +4 -5
  59. payi/types/limits/{tag_delete_response.py → property_update_response.py} +3 -3
  60. payi/types/requests/request_id/property_update_params.py +2 -2
  61. payi/types/requests/response_id/property_update_params.py +2 -2
  62. payi/types/shared/__init__.py +2 -0
  63. payi/types/shared/api_error.py +18 -0
  64. payi/types/shared/pay_i_common_models_budget_management_create_limit_base.py +3 -3
  65. payi/types/shared/properties_request.py +11 -0
  66. payi/types/shared/xproxy_result.py +2 -0
  67. payi/types/shared_params/pay_i_common_models_budget_management_create_limit_base.py +3 -3
  68. payi/types/use_cases/definitions/limit_config_create_params.py +3 -3
  69. payi/types/use_cases/property_update_params.py +2 -2
  70. {payi-0.1.0a107.dist-info → payi-0.1.0a137.dist-info}/METADATA +6 -6
  71. {payi-0.1.0a107.dist-info → payi-0.1.0a137.dist-info}/RECORD +73 -75
  72. payi/resources/categories/fixed_cost_resources.py +0 -196
  73. payi/resources/limits/tags.py +0 -507
  74. payi/types/categories/fixed_cost_resource_create_params.py +0 -21
  75. payi/types/limits/limit_tags.py +0 -16
  76. payi/types/limits/tag_create_params.py +0 -13
  77. payi/types/limits/tag_create_response.py +0 -10
  78. payi/types/limits/tag_list_response.py +0 -10
  79. payi/types/limits/tag_remove_response.py +0 -10
  80. payi/types/limits/tag_update_params.py +0 -13
  81. payi/types/limits/tag_update_response.py +0 -10
  82. {payi-0.1.0a107.dist-info → payi-0.1.0a137.dist-info}/WHEEL +0 -0
  83. {payi-0.1.0a107.dist-info → payi-0.1.0a137.dist-info}/licenses/LICENSE +0 -0
payi/lib/helpers.py CHANGED
@@ -1,16 +1,24 @@
1
+ from __future__ import annotations
2
+
1
3
  import os
2
- from typing import Dict, List, Union
4
+ import json
5
+ from typing import Any, Dict, List, Union
6
+
7
+ __all__ = ['_set_attr_safe']
3
8
 
4
9
  PAYI_BASE_URL = "https://api.pay-i.com"
5
10
 
6
11
  class PayiHeaderNames:
7
12
  limit_ids:str = "xProxy-Limit-IDs"
8
13
  request_tags:str = "xProxy-Request-Tags"
14
+ request_properties:str = "xProxy-Request-Properties"
9
15
  use_case_id:str = "xProxy-UseCase-ID"
10
16
  use_case_name:str = "xProxy-UseCase-Name"
11
17
  use_case_version:str = "xProxy-UseCase-Version"
12
18
  use_case_step:str = "xProxy-UseCase-Step"
19
+ use_case_properties:str = "xProxy-UseCase-Properties"
13
20
  user_id:str = "xProxy-User-ID"
21
+ account_name:str = "xProxy-Account-Name"
14
22
  price_as_category:str = "xProxy-PriceAs-Category"
15
23
  price_as_resource:str = "xProxy-PriceAs-Resource"
16
24
  provider_base_uri = "xProxy-Provider-BaseUri"
@@ -24,7 +32,24 @@ class PayiCategories:
24
32
  aws_bedrock:str = "system.aws.bedrock"
25
33
  google_vertex:str = "system.google.vertex"
26
34
 
27
- def create_limit_header_from_ids(limit_ids: List[str]) -> Dict[str, str]:
35
+ class PayiPropertyNames:
36
+ failure:str = "system.failure"
37
+ failure_description:str = "system.failure.description"
38
+
39
+ account_name:str = "system.account_name"
40
+ use_case_step:str = "system.use_case_step"
41
+ user_id:str = "system.user_id"
42
+
43
+ aws_bedrock_guardrail_id:str = "system.aws.bedrock.guardrail.id"
44
+ aws_bedrock_guardrail_version:str = "system.aws.bedrock.guardrail.version"
45
+ aws_bedrock_guardrail_action:str = "system.aws.bedrock.guardrail.action"
46
+
47
+ class PayiResourceScopes:
48
+ global_scope: str = "global"
49
+ datazone_scope: str = "datazone"
50
+ region_scope: str = "region"
51
+
52
+ def create_limit_header_from_ids(*, limit_ids: List[str]) -> Dict[str, str]:
28
53
  if not isinstance(limit_ids, list): # type: ignore
29
54
  raise TypeError("limit_ids must be a list")
30
55
 
@@ -32,7 +57,7 @@ def create_limit_header_from_ids(limit_ids: List[str]) -> Dict[str, str]:
32
57
 
33
58
  return { PayiHeaderNames.limit_ids: ",".join(valid_ids) } if valid_ids else {}
34
59
 
35
- def create_request_header_from_tags(request_tags: List[str]) -> Dict[str, str]:
60
+ def create_request_header_from_tags(*, request_tags: List[str]) -> Dict[str, str]:
36
61
  if not isinstance(request_tags, list): # type: ignore
37
62
  raise TypeError("request_tags must be a list")
38
63
 
@@ -40,14 +65,21 @@ def create_request_header_from_tags(request_tags: List[str]) -> Dict[str, str]:
40
65
 
41
66
  return { PayiHeaderNames.request_tags: ",".join(valid_tags) } if valid_tags else {}
42
67
 
68
+ def _compact_json(data: Any) -> str:
69
+ return json.dumps(data, separators=(',', ':'))
70
+
43
71
  def create_headers(
72
+ *,
44
73
  limit_ids: Union[List[str], None] = None,
45
74
  request_tags: Union[List[str], None] = None,
46
75
  user_id: Union[str, None] = None,
76
+ account_name: Union[str, None] = None,
47
77
  use_case_id: Union[str, None] = None,
48
78
  use_case_name: Union[str, None] = None,
49
79
  use_case_version: Union[int, None] = None,
50
80
  use_case_step: Union[str, None] = None,
81
+ use_case_properties: Union[Dict[str, str], None] = None,
82
+ request_properties: Union[Dict[str, str], None] = None,
51
83
  price_as_category: Union[str, None] = None,
52
84
  price_as_resource: Union[str, None] = None,
53
85
  resource_scope: Union[str, None] = None,
@@ -55,17 +87,23 @@ def create_headers(
55
87
  headers: Dict[str, str] = {}
56
88
 
57
89
  if limit_ids:
58
- headers.update(create_limit_header_from_ids(limit_ids))
90
+ headers.update(create_limit_header_from_ids(limit_ids=limit_ids))
59
91
  if request_tags:
60
- headers.update(create_request_header_from_tags(request_tags))
92
+ headers.update(create_request_header_from_tags(request_tags=request_tags))
61
93
  if user_id:
62
94
  headers.update({ PayiHeaderNames.user_id: user_id})
95
+ if account_name:
96
+ headers.update({ PayiHeaderNames.account_name: account_name})
63
97
  if use_case_id:
64
98
  headers.update({ PayiHeaderNames.use_case_id: use_case_id})
65
99
  if use_case_name:
66
100
  headers.update({ PayiHeaderNames.use_case_name: use_case_name})
67
101
  if use_case_version:
68
102
  headers.update({ PayiHeaderNames.use_case_version: str(use_case_version)})
103
+ if use_case_properties:
104
+ headers.update({ PayiHeaderNames.use_case_properties: _compact_json(use_case_properties) })
105
+ if request_properties:
106
+ headers.update({ PayiHeaderNames.request_properties: _compact_json(request_properties) })
69
107
  if use_case_step:
70
108
  headers.update({ PayiHeaderNames.use_case_step: use_case_step})
71
109
  if price_as_category:
@@ -101,3 +139,22 @@ def payi_aws_bedrock_url(payi_base_url: Union[str, None] = None) -> str:
101
139
 
102
140
  # def payi_google_vertex_url(payi_base_url: Union[str, None] = None) -> str:
103
141
  # return _resolve_payi_base_url(payi_base_url=payi_base_url) + "/api/v1/proxy/google.vertex"
142
+
143
+ def _set_attr_safe(o: Any, attr_name: str, attr_value: Any) -> None:
144
+ try:
145
+ if hasattr(o, '__pydantic_private__') and o.__pydantic_private__ is not None:
146
+ o.__pydantic_private__[attr_name] = attr_value
147
+
148
+ if hasattr(o, '__dict__'):
149
+ # Use object.__setattr__ to bypass Pydantic validation
150
+ # This allows setting attributes outside the model schema without triggering forbid=true errors
151
+ object.__setattr__(o, attr_name, attr_value)
152
+ elif isinstance(o, dict):
153
+ o[attr_name] = attr_value
154
+ else:
155
+ setattr(o, attr_name, attr_value)
156
+
157
+ except Exception:
158
+ # _g_logger.debug(f"Could not set attribute {attr_name}: {e}")
159
+ pass
160
+