payi 0.1.0a110__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 +53 -1
  27. payi/lib/instrument.py +404 -668
  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.0a110.dist-info → payi-0.1.0a137.dist-info}/METADATA +6 -6
  71. {payi-0.1.0a110.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.0a110.dist-info → payi-0.1.0a137.dist-info}/WHEEL +0 -0
  83. {payi-0.1.0a110.dist-info → payi-0.1.0a137.dist-info}/licenses/LICENSE +0 -0
payi/lib/helpers.py CHANGED
@@ -1,15 +1,22 @@
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"
14
21
  account_name:str = "xProxy-Account-Name"
15
22
  price_as_category:str = "xProxy-PriceAs-Category"
@@ -25,6 +32,23 @@ class PayiCategories:
25
32
  aws_bedrock:str = "system.aws.bedrock"
26
33
  google_vertex:str = "system.google.vertex"
27
34
 
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
+
28
52
  def create_limit_header_from_ids(*, limit_ids: List[str]) -> Dict[str, str]:
29
53
  if not isinstance(limit_ids, list): # type: ignore
30
54
  raise TypeError("limit_ids must be a list")
@@ -41,6 +65,9 @@ def create_request_header_from_tags(*, request_tags: List[str]) -> Dict[str, str
41
65
 
42
66
  return { PayiHeaderNames.request_tags: ",".join(valid_tags) } if valid_tags else {}
43
67
 
68
+ def _compact_json(data: Any) -> str:
69
+ return json.dumps(data, separators=(',', ':'))
70
+
44
71
  def create_headers(
45
72
  *,
46
73
  limit_ids: Union[List[str], None] = None,
@@ -51,6 +78,8 @@ def create_headers(
51
78
  use_case_name: Union[str, None] = None,
52
79
  use_case_version: Union[int, None] = None,
53
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,
54
83
  price_as_category: Union[str, None] = None,
55
84
  price_as_resource: Union[str, None] = None,
56
85
  resource_scope: Union[str, None] = None,
@@ -71,6 +100,10 @@ def create_headers(
71
100
  headers.update({ PayiHeaderNames.use_case_name: use_case_name})
72
101
  if use_case_version:
73
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) })
74
107
  if use_case_step:
75
108
  headers.update({ PayiHeaderNames.use_case_step: use_case_step})
76
109
  if price_as_category:
@@ -106,3 +139,22 @@ def payi_aws_bedrock_url(payi_base_url: Union[str, None] = None) -> str:
106
139
 
107
140
  # def payi_google_vertex_url(payi_base_url: Union[str, None] = None) -> str:
108
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
+