models-provider 0.1.0__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.
- models_provider-0.1.0/.gitignore +9 -0
- models_provider-0.1.0/LICENSE +21 -0
- models_provider-0.1.0/PKG-INFO +132 -0
- models_provider-0.1.0/README.md +107 -0
- models_provider-0.1.0/pyproject.toml +47 -0
- models_provider-0.1.0/src/models_provider/__init__.py +55 -0
- models_provider-0.1.0/src/models_provider/auth.py +1065 -0
- models_provider-0.1.0/src/models_provider/catalogue.py +258 -0
- models_provider-0.1.0/src/models_provider/client.py +99 -0
- models_provider-0.1.0/src/models_provider/errors.py +14 -0
- models_provider-0.1.0/src/models_provider/providers/__init__.py +98 -0
- models_provider-0.1.0/src/models_provider/providers/cursor.py +1009 -0
- models_provider-0.1.0/src/models_provider/providers/litellm.py +379 -0
- models_provider-0.1.0/src/models_provider/providers/openai.py +800 -0
- models_provider-0.1.0/src/models_provider/py.typed +0 -0
- models_provider-0.1.0/src/models_provider/usage.py +311 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Giovanni Gravili
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: models-provider
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An independent models.dev catalogue and interchangeable model provider layer.
|
|
5
|
+
Project-URL: Repository, https://github.com/ghovax/models-provider
|
|
6
|
+
Project-URL: Issues, https://github.com/ghovax/models-provider/issues
|
|
7
|
+
Author: Giovanni Gravili
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai,langchain,llm,models,providers
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.13
|
|
19
|
+
Requires-Dist: httpx>=0.28.0
|
|
20
|
+
Requires-Dist: langchain-core>=1.0
|
|
21
|
+
Requires-Dist: litellm>=1.60.0
|
|
22
|
+
Requires-Dist: pydantic>=2.0.0
|
|
23
|
+
Requires-Dist: websockets<16,>=15.0
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# Models Provider
|
|
27
|
+
|
|
28
|
+
Models Provider gives applications one interface for selecting models, resolving provider access, creating chat models, and collecting usage. Model metadata is loaded privately from the public [models.dev catalogue](https://models.dev).
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```console
|
|
33
|
+
pip install models-provider
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Public flow
|
|
37
|
+
|
|
38
|
+
Pass provider values directly to `Models`, then select a provider-qualified model:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from models_provider import Models
|
|
42
|
+
|
|
43
|
+
models = Models({
|
|
44
|
+
"openai": "OPENAI_API_KEY",
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
model = models.chat(
|
|
48
|
+
"openai/gpt-4.1-mini",
|
|
49
|
+
temperature=0.2,
|
|
50
|
+
top_p=0.9,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
answer = model.invoke("Explain spaced repetition in two sentences.")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`Models()` fetches the fixed models.dev catalogue once during initialization and caches it internally. Applications do not load or construct a catalogue.
|
|
57
|
+
|
|
58
|
+
The model identifier describes the model publisher, not the authentication mechanism. The access implementation is selected internally from the provider and the supplied values. For example, `openai/gpt-5` remains the model identifier when the available access is an API key or an OpenAI account session.
|
|
59
|
+
|
|
60
|
+
## Provider values
|
|
61
|
+
|
|
62
|
+
The constructor accepts one ordinary dictionary. Values can be literal credentials, environment-variable names, or provider-specific mappings:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
Models({"openai": "sk-proj-...7Qx2"})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
Models({"openai": "OPENAI_API_KEY"})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
An uppercase environment-variable name is resolved from the process environment. Persistence is owned by the embedding application; Models Provider does not expose a credential-store abstraction or load credential files.
|
|
73
|
+
|
|
74
|
+
## OAuth
|
|
75
|
+
|
|
76
|
+
OAuth values use the same dictionary. The host controls how the authorization URL is displayed:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
models = Models()
|
|
80
|
+
|
|
81
|
+
authorization = await models.sign_in("openai")
|
|
82
|
+
# The host uses authorization.url to open the authorization page for the user.
|
|
83
|
+
await authorization.complete()
|
|
84
|
+
|
|
85
|
+
model = models.chat("openai/gpt-5", authorization=authorization)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The login flow and token refresh are provider-owned. Each authorization is independent, so the same `Models` instance can serve different users. The host decides whether and how to persist a user's authorization values.
|
|
89
|
+
|
|
90
|
+
## Model contract
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
models.chat(
|
|
94
|
+
"provider/model",
|
|
95
|
+
temperature=0.2,
|
|
96
|
+
top_p=0.9,
|
|
97
|
+
reasoning_effort="high",
|
|
98
|
+
max_output_tokens=512,
|
|
99
|
+
) -> BaseChatModel
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Request settings are ordinary keyword arguments. The selected access implementation validates and translates them to its transport. There is no public options object and no provider-specific access class required from the caller.
|
|
103
|
+
|
|
104
|
+
## Usage values
|
|
105
|
+
|
|
106
|
+
Normalized usage is grouped by measurement type:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
usage.tokens.input_tokens
|
|
110
|
+
usage.tokens.reasoning_tokens
|
|
111
|
+
usage.cache.cache_read_tokens
|
|
112
|
+
usage.audio.output_audio_tokens
|
|
113
|
+
usage.cost.cost_usd
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`UsageLedger` owns accumulation when an application records multiple responses.
|
|
117
|
+
|
|
118
|
+
## Ownership
|
|
119
|
+
|
|
120
|
+
Models Provider owns:
|
|
121
|
+
|
|
122
|
+
- the private models.dev catalogue and its built-in cache;
|
|
123
|
+
- provider and model selection;
|
|
124
|
+
- provider-specific authentication and transport;
|
|
125
|
+
- request-option normalization;
|
|
126
|
+
- usage normalization.
|
|
127
|
+
|
|
128
|
+
The embedding application owns:
|
|
129
|
+
|
|
130
|
+
- the provider-values dictionary;
|
|
131
|
+
- credential persistence, if needed;
|
|
132
|
+
- application workflows, sessions, tools, permissions, and files.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Models Provider
|
|
2
|
+
|
|
3
|
+
Models Provider gives applications one interface for selecting models, resolving provider access, creating chat models, and collecting usage. Model metadata is loaded privately from the public [models.dev catalogue](https://models.dev).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```console
|
|
8
|
+
pip install models-provider
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Public flow
|
|
12
|
+
|
|
13
|
+
Pass provider values directly to `Models`, then select a provider-qualified model:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from models_provider import Models
|
|
17
|
+
|
|
18
|
+
models = Models({
|
|
19
|
+
"openai": "OPENAI_API_KEY",
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
model = models.chat(
|
|
23
|
+
"openai/gpt-4.1-mini",
|
|
24
|
+
temperature=0.2,
|
|
25
|
+
top_p=0.9,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
answer = model.invoke("Explain spaced repetition in two sentences.")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`Models()` fetches the fixed models.dev catalogue once during initialization and caches it internally. Applications do not load or construct a catalogue.
|
|
32
|
+
|
|
33
|
+
The model identifier describes the model publisher, not the authentication mechanism. The access implementation is selected internally from the provider and the supplied values. For example, `openai/gpt-5` remains the model identifier when the available access is an API key or an OpenAI account session.
|
|
34
|
+
|
|
35
|
+
## Provider values
|
|
36
|
+
|
|
37
|
+
The constructor accepts one ordinary dictionary. Values can be literal credentials, environment-variable names, or provider-specific mappings:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
Models({"openai": "sk-proj-...7Qx2"})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
Models({"openai": "OPENAI_API_KEY"})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
An uppercase environment-variable name is resolved from the process environment. Persistence is owned by the embedding application; Models Provider does not expose a credential-store abstraction or load credential files.
|
|
48
|
+
|
|
49
|
+
## OAuth
|
|
50
|
+
|
|
51
|
+
OAuth values use the same dictionary. The host controls how the authorization URL is displayed:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
models = Models()
|
|
55
|
+
|
|
56
|
+
authorization = await models.sign_in("openai")
|
|
57
|
+
# The host uses authorization.url to open the authorization page for the user.
|
|
58
|
+
await authorization.complete()
|
|
59
|
+
|
|
60
|
+
model = models.chat("openai/gpt-5", authorization=authorization)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The login flow and token refresh are provider-owned. Each authorization is independent, so the same `Models` instance can serve different users. The host decides whether and how to persist a user's authorization values.
|
|
64
|
+
|
|
65
|
+
## Model contract
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
models.chat(
|
|
69
|
+
"provider/model",
|
|
70
|
+
temperature=0.2,
|
|
71
|
+
top_p=0.9,
|
|
72
|
+
reasoning_effort="high",
|
|
73
|
+
max_output_tokens=512,
|
|
74
|
+
) -> BaseChatModel
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Request settings are ordinary keyword arguments. The selected access implementation validates and translates them to its transport. There is no public options object and no provider-specific access class required from the caller.
|
|
78
|
+
|
|
79
|
+
## Usage values
|
|
80
|
+
|
|
81
|
+
Normalized usage is grouped by measurement type:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
usage.tokens.input_tokens
|
|
85
|
+
usage.tokens.reasoning_tokens
|
|
86
|
+
usage.cache.cache_read_tokens
|
|
87
|
+
usage.audio.output_audio_tokens
|
|
88
|
+
usage.cost.cost_usd
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`UsageLedger` owns accumulation when an application records multiple responses.
|
|
92
|
+
|
|
93
|
+
## Ownership
|
|
94
|
+
|
|
95
|
+
Models Provider owns:
|
|
96
|
+
|
|
97
|
+
- the private models.dev catalogue and its built-in cache;
|
|
98
|
+
- provider and model selection;
|
|
99
|
+
- provider-specific authentication and transport;
|
|
100
|
+
- request-option normalization;
|
|
101
|
+
- usage normalization.
|
|
102
|
+
|
|
103
|
+
The embedding application owns:
|
|
104
|
+
|
|
105
|
+
- the provider-values dictionary;
|
|
106
|
+
- credential persistence, if needed;
|
|
107
|
+
- application workflows, sessions, tools, permissions, and files.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "models-provider"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "An independent models.dev catalogue and interchangeable model provider layer."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.13"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Giovanni Gravili" }]
|
|
14
|
+
keywords = ["ai", "llm", "models", "providers", "langchain"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"httpx>=0.28.0",
|
|
26
|
+
"langchain-core>=1.0",
|
|
27
|
+
"litellm>=1.60.0",
|
|
28
|
+
"pydantic>=2.0.0",
|
|
29
|
+
"websockets>=15.0,<16",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Repository = "https://github.com/ghovax/models-provider"
|
|
34
|
+
Issues = "https://github.com/ghovax/models-provider/issues"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.wheel]
|
|
37
|
+
packages = ["src/models_provider"]
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build]
|
|
40
|
+
include = ["src/models_provider/**/*.py", "src/models_provider/py.typed"]
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
line-length = 100
|
|
44
|
+
target-version = "py313"
|
|
45
|
+
|
|
46
|
+
[tool.ruff.lint]
|
|
47
|
+
select = ["E4", "E7", "E9", "F", "B", "ASYNC", "RUF006", "RUF012", "RUF018", "RUF019"]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Public model-selection and authorization interface."""
|
|
2
|
+
|
|
3
|
+
from .auth import (
|
|
4
|
+
DeviceLoginFlow,
|
|
5
|
+
HostedAuthorization,
|
|
6
|
+
LoginFlow,
|
|
7
|
+
OAuthAdapter,
|
|
8
|
+
OAuthAuthorization,
|
|
9
|
+
OAuthAuthorizationRequest,
|
|
10
|
+
OAuthConfiguration,
|
|
11
|
+
OAuthLoginFlow,
|
|
12
|
+
OAuthProvider,
|
|
13
|
+
OAuthTokens,
|
|
14
|
+
)
|
|
15
|
+
from .catalogue import ModelProvider, ModelRecord, ProviderRecord
|
|
16
|
+
from .client import Models
|
|
17
|
+
from .errors import AuthenticationError, ContextWindowError
|
|
18
|
+
from .usage import (
|
|
19
|
+
AudioUsage,
|
|
20
|
+
CacheUsage,
|
|
21
|
+
CostUsage,
|
|
22
|
+
ModelUsage,
|
|
23
|
+
TokenUsage,
|
|
24
|
+
UsageLedger,
|
|
25
|
+
UsageSnapshot,
|
|
26
|
+
UsageWindow,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"AuthenticationError",
|
|
32
|
+
"AudioUsage",
|
|
33
|
+
"CacheUsage",
|
|
34
|
+
"ContextWindowError",
|
|
35
|
+
"CostUsage",
|
|
36
|
+
"DeviceLoginFlow",
|
|
37
|
+
"HostedAuthorization",
|
|
38
|
+
"LoginFlow",
|
|
39
|
+
"ModelProvider",
|
|
40
|
+
"ModelRecord",
|
|
41
|
+
"ModelUsage",
|
|
42
|
+
"Models",
|
|
43
|
+
"OAuthAdapter",
|
|
44
|
+
"OAuthAuthorization",
|
|
45
|
+
"OAuthAuthorizationRequest",
|
|
46
|
+
"OAuthConfiguration",
|
|
47
|
+
"OAuthLoginFlow",
|
|
48
|
+
"OAuthProvider",
|
|
49
|
+
"OAuthTokens",
|
|
50
|
+
"ProviderRecord",
|
|
51
|
+
"TokenUsage",
|
|
52
|
+
"UsageLedger",
|
|
53
|
+
"UsageSnapshot",
|
|
54
|
+
"UsageWindow",
|
|
55
|
+
]
|