forked from openai/openai-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput-tokens.ts
More file actions
249 lines (223 loc) · 9.05 KB
/
Copy pathinput-tokens.ts
File metadata and controls
249 lines (223 loc) · 9.05 KB
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
242
243
244
245
246
247
248
249
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
import { APIResource } from '../../../core/resource';
import * as ResponsesAPI from './responses';
import { APIPromise } from '../../../core/api-promise';
import { buildHeaders } from '../../../internal/headers';
import { RequestOptions } from '../../../internal/request-options';
export class InputTokens extends APIResource {
/**
* Returns input token counts of the request.
*
* Returns an object with `object` set to `response.input_tokens` and an
* `input_tokens` count.
*
* @example
* ```ts
* const response =
* await client.beta.responses.inputTokens.count();
* ```
*/
count(
params: InputTokenCountParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<InputTokenCountResponse> {
const { betas, ...body } = params ?? {};
return this._client.post('/responses/input_tokens?beta=true', {
body,
...options,
headers: buildHeaders([
{ ...(betas?.toString() != null ? { 'openai-beta': betas?.toString() } : undefined) },
options?.headers,
]),
__security: { bearerAuth: true },
});
}
}
export interface InputTokenCountResponse {
input_tokens: number;
object: 'response.input_tokens';
}
export interface InputTokenCountParams {
/**
* Body param: The conversation that this response belongs to. Items from this
* conversation are prepended to `input_items` for this response request. Input
* items and output items from this response are automatically added to this
* conversation after this response completes.
*/
conversation?: string | ResponsesAPI.BetaResponseConversationParam | null;
/**
* Body param: Text, image, or file inputs to the model, used to generate a
* response
*/
input?: string | Array<ResponsesAPI.BetaResponseInputItem> | null;
/**
* Body param: A system (or developer) message inserted into the model's context.
* When used along with `previous_response_id`, the instructions from a previous
* response will not be carried over to the next response. This makes it simple to
* swap out system (or developer) messages in new responses.
*/
instructions?: string | null;
/**
* Body param: Model ID used to generate the response, like `gpt-4o` or `o3`.
* OpenAI offers a wide range of models with different capabilities, performance
* characteristics, and price points. Refer to the
* [model guide](https://platform.openai.com/docs/models) to browse and compare
* available models.
*/
model?: string | null;
/**
* Body param: Whether to allow the model to run tool calls in parallel.
*/
parallel_tool_calls?: boolean | null;
/**
* Body param: A model-owned style preset to apply to this request. Omit this
* parameter to use the model's default style. Supported values may expand over
* time. Values must be at most 64 characters.
*/
personality?: (string & {}) | 'friendly' | 'pragmatic';
/**
* Body param: The unique ID of the previous response to the model. Use this to
* create multi-turn conversations. Learn more about
* [conversation state](https://platform.openai.com/docs/guides/conversation-state).
* Cannot be used in conjunction with `conversation`.
*/
previous_response_id?: string | null;
/**
* Body param: **gpt-5 and o-series models only** Configuration options for
* [reasoning models](https://platform.openai.com/docs/guides/reasoning).
*/
reasoning?: InputTokenCountParams.Reasoning | null;
/**
* Body param: Configuration options for a text response from the model. Can be
* plain text or structured JSON data. Learn more:
*
* - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
* - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
*/
text?: InputTokenCountParams.Text | null;
/**
* Body param: Controls which tool the model should use, if any.
*/
tool_choice?:
| ResponsesAPI.BetaToolChoiceOptions
| ResponsesAPI.BetaToolChoiceAllowed
| ResponsesAPI.BetaToolChoiceTypes
| ResponsesAPI.BetaToolChoiceFunction
| ResponsesAPI.BetaToolChoiceMcp
| ResponsesAPI.BetaToolChoiceCustom
| InputTokenCountParams.BetaSpecificProgrammaticToolCallingParam
| ResponsesAPI.BetaToolChoiceApplyPatch
| ResponsesAPI.BetaToolChoiceShell
| null;
/**
* Body param: An array of tools the model may call while generating a response.
* You can specify which tool to use by setting the `tool_choice` parameter.
*/
tools?: Array<ResponsesAPI.BetaTool> | null;
/**
* @deprecated Body param: The truncation strategy to use for the model response. -
* `auto`: If the input to this Response exceeds the model's context window size,
* the model will truncate the response to fit the context window by dropping items
* from the beginning of the conversation. - `disabled` (default): If the input
* size will exceed the context window size for a model, the request will fail with
* a 400 error.
*/
truncation?: 'auto' | 'disabled';
/**
* Header param: Optional beta features to enable for this request.
*/
betas?: Array<'responses_multi_agent=v1'>;
}
export namespace InputTokenCountParams {
/**
* **gpt-5 and o-series models only** Configuration options for
* [reasoning models](https://platform.openai.com/docs/guides/reasoning).
*/
export interface Reasoning {
/**
* Controls which reasoning items are rendered back to the model on later turns. If
* omitted or set to `auto`, the model determines the context mode. The `gpt-5.6`
* model family defaults to `all_turns`; earlier models default to `current_turn`.
*
* When returned on a response, this is the effective reasoning context mode used
* for the response.
*/
context?: 'auto' | 'current_turn' | 'all_turns' | null;
/**
* Constrains effort on reasoning for reasoning models. Currently supported values
* are `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`. Reducing
* reasoning effort can result in faster responses and fewer tokens used on
* reasoning in a response. Not all reasoning models support every value. See the
* [reasoning guide](https://platform.openai.com/docs/guides/reasoning) for
* model-specific support.
*/
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | null;
/**
* @deprecated **Deprecated:** use `summary` instead.
*
* A summary of the reasoning performed by the model. This can be useful for
* debugging and understanding the model's reasoning process. One of `auto`,
* `concise`, or `detailed`.
*/
generate_summary?: 'auto' | 'concise' | 'detailed' | null;
/**
* Controls the reasoning execution mode for the request.
*
* When returned on a response, this is the effective execution mode.
*/
mode?: (string & {}) | 'standard' | 'pro';
/**
* A summary of the reasoning performed by the model. This can be useful for
* debugging and understanding the model's reasoning process. One of `auto`,
* `concise`, or `detailed`.
*
* `concise` is supported for `computer-use-preview` models and all reasoning
* models after `gpt-5`.
*/
summary?: 'auto' | 'concise' | 'detailed' | null;
}
/**
* Configuration options for a text response from the model. Can be plain text or
* structured JSON data. Learn more:
*
* - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
* - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
*/
export interface Text {
/**
* An object specifying the format that the model must output.
*
* Configuring `{ "type": "json_schema" }` enables Structured Outputs, which
* ensures the model will match your supplied JSON schema. Learn more in the
* [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
*
* The default format is `{ "type": "text" }` with no additional options.
*
* **Not recommended for gpt-4o and newer models:**
*
* Setting to `{ "type": "json_object" }` enables the older JSON mode, which
* ensures the message the model generates is valid JSON. Using `json_schema` is
* preferred for models that support it.
*/
format?: ResponsesAPI.BetaResponseFormatTextConfig;
/**
* Constrains the verbosity of the model's response. Lower values will result in
* more concise responses, while higher values will result in more verbose
* responses. Currently supported values are `low`, `medium`, and `high`. The
* default is `medium`.
*/
verbosity?: 'low' | 'medium' | 'high' | null;
}
export interface BetaSpecificProgrammaticToolCallingParam {
/**
* The tool to call. Always `programmatic_tool_calling`.
*/
type: 'programmatic_tool_calling';
}
}
export declare namespace InputTokens {
export {
type InputTokenCountResponse as InputTokenCountResponse,
type InputTokenCountParams as InputTokenCountParams,
};
}