1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2025 Michael Dippery <michael@monkey-robot.com>
//! An implementation of a client for the OpenAI API.
//!
//! This provider implements various traits from [cogito] to provide a uniform
//! way to access the OpenAI API. This makes it easy to swap out other
//! providers for OpenAI in your application, or vice versa.
//!
//! This library assumes you pass authentication tokens for the OpenAI API
//! using [`cogito::service::Auth`]. **This means that you are solely
//! responsible for paying the costs of API access; the Cogito developers
//! are not responsible for costs you incur while using this library.**
//!
//! # Cost
//!
//! There's no such thing as a free lunch, and there's no such thing as free OpenAI access,
//! even if OpenAI is a "non-profit" that is building its technology for the betterment of
//! humanity (and not Sam Altman's bank account). When you create an OpenAI API client,
//! you will need to select an [`OpenAIModel`]. Models are billed on a per-token basis, where
//! a token is the smallest unit of text that the model reads and processes. There are three
//! types of tokens: input tokens, cached input tokens, and output tokens.
//!
//! - **Input tokens** are the token used in any _requests_ made to the OpenAPI AI. This is
//! the "prompt" that users of this library send to OpenAI for summarization.
//! - **Cached input tokens** are input tokens that have been reused by GPT. Input tokens are
//! reused by prompts that have a common prefix, as described
//! [here](https://openai.com/index/api-prompt-caching/).
//! - **Output tokens** are tokens generated in the output that is sent back to a client in
//! response to a request.
//!
//! Prices are expressed in US dollars per $1 million tokens. As of 17 July 2025, the prices
//! for each model are as follows.
//!
//! For the latest pricing, see OpenAI's [pricing][OpenAI's platform pricing documentation]
//! docs.
//!
//! | Model | Designation | Input | Cached Input | Output |
//! |------------|--------------------|---------:|-------------:|--------:|
//! | Gpt5 | gpt-5 | $1.25 | $0.125 | $10.00 |
//! | Gpt5mini | gpt-5-mini | $0.25 | $0.025 | $2.00 |
//! | Gpt5nano | gpt-5-nano | $0.05 | $0.005 | $0.40 |
//! | Gpt4_1nano | gpt-4.1-nano | $0.10 | $0.025 | $0.40 |
//! | Gpt4omini | gpt-4o-mini | $0.15 | $0.075 | $0.60 |
//! | Gpt4_1mini | gpt-4.1-mini | $0.40 | $0.10 | $1.60 |
//! | O4mini | o4-mini | $1.10 | $0.275 | $4.40 |
//! | O3mini | o3-mini | $1.10 | $0.55 | $4.40 |
//! | Gpt4_1 | gpt-4.1 | $2.00 | $0.50 | $8.00 |
//! | O3 | o3 | $2.00 | $0.50 | $8.00 |
//! | Gpt4o | gpt-4o | $2.50 | $1.25 | $10.00 |
//! | ChatGpt4o | chatgpt-4o-latest | $5.00 | - | $15.00 |
//! | O1 | o1 | $15.00 | $7.50 | $60.00 |
//! | O3pro | o3-pro | $20.00 | - | $80.00 |
//! | 01pro | o1-pro | $150.00 | - | $600.00 |
//!
//! [cogito]: https://docs.rs/cogito
//! [`OpenAIClient::new()`]: client::OpenAIClient::new
//! [`cogito::service::Auth`]: https://docs.rs/cogito/latest/cogito/service/struct.Auth.html
//! [OpenAI's platform pricing documentation]: https://platform.openai.com/docs/pricing
use AiModel;
use ;
use fmt;
/// Available OpenAI GPT models.
///
/// For more information on the differences between each model, see the
/// [OpenAI model documentation].
///
/// The [default](OpenAIModel::default()) is [gpt-4o](OpenAIModel::Gpt4o),
/// which OpenAI describes as "the best model to use for most tasks".
/// [According to its docs][1], [gpt-4.1](OpenAIModel::Gpt4_1) "offers a solid
/// combination of intelligence, speed, and cost effectiveness". If you are on
/// a budget, consider using [gpt-4.1-nano](OpenAIModel::Gpt4_1nano), the
/// [least expensive](OpenAIModel::cheapest()) model.
///
/// # Cost
///
/// OpenAI API usage has a cost, and the cost of each model differs;
/// naturally, the more powerful models cost more to use. See the
/// [cost breakdown] in the `cogito_openai` module documentation
/// for more details, or visit OpenAI's [pricing] docs for the latest prices.
///
/// [1]: https://platform.openai.com/docs/guides/text?api-mode=responses#choosing-a-model
/// [cost breakdown]: self#Cost
/// [OpenAI model documentation]: https://platform.openai.com/docs/models
/// [pricing]: https://platform.openai.com/docs/pricing
/// Convenience module for splat imports.
///
/// You can import the most common traits and data structures into your
/// project using
///
/// ```
/// use cogito_openai::prelude::*;
/// ```