GPTRouter 1.0.6__tar.gz → 1.0.7__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GPTRouter
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: A Python package for working with GPTRouter APIs
5
5
  Author-email: sirjanpreet@writesonic.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GPTRouter
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: A Python package for working with GPTRouter APIs
5
5
  Author-email: sirjanpreet@writesonic.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -1,4 +1,4 @@
1
- from pydantic import ConfigDict, BaseModel, Field
1
+ from pydantic import ConfigDict, BaseModel, Field, model_validator
2
2
  from enum import Enum
3
3
  from typing import Dict, List, Literal, Optional, Any, Union
4
4
  from humps import camelize
@@ -90,6 +90,18 @@ class Usage(BaseModel):
90
90
  prompt_tokens: Optional[int] = None
91
91
  total_tokens: Optional[int] = None
92
92
 
93
+ @model_validator(mode="before")
94
+ @classmethod
95
+ def unwrap_nested_usage(cls, data):
96
+ """Handle API response where token counts are nested under a 'usage' key.
97
+
98
+ The API returns: {"meta": {"usage": {"prompt_tokens": N, ...}}}
99
+ but this model expects flat fields: {"prompt_tokens": N, ...}
100
+ """
101
+ if isinstance(data, dict) and "usage" in data and isinstance(data["usage"], dict):
102
+ return data["usage"]
103
+ return data
104
+
93
105
 
94
106
  class Choice(BaseModel):
95
107
  index: int
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name="GPTRouter",
8
- version="1.0.6",
8
+ version="1.0.7",
9
9
  description="A Python package for working with GPTRouter APIs",
10
10
  long_description=long_description,
11
11
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes