|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import { APIResource } from '../../core/resource'; |
| 4 | +import * as Shared from '../shared'; |
| 5 | +import * as ResponsesAPI from './responses'; |
| 6 | +import { APIPromise } from '../../core/api-promise'; |
| 7 | +import { RequestOptions } from '../../internal/request-options'; |
| 8 | + |
| 9 | +export class InputTokens extends APIResource { |
| 10 | + /** |
| 11 | + * Get input token counts |
| 12 | + * |
| 13 | + * @example |
| 14 | + * ```ts |
| 15 | + * const response = await client.responses.inputTokens.count(); |
| 16 | + * ``` |
| 17 | + */ |
| 18 | + count( |
| 19 | + body: InputTokenCountParams | null | undefined = {}, |
| 20 | + options?: RequestOptions, |
| 21 | + ): APIPromise<InputTokenCountResponse> { |
| 22 | + return this._client.post('/responses/input_tokens', { body, ...options }); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +export interface InputTokenCountResponse { |
| 27 | + input_tokens: number; |
| 28 | + |
| 29 | + object: 'response.input_tokens'; |
| 30 | +} |
| 31 | + |
| 32 | +export interface InputTokenCountParams { |
| 33 | + /** |
| 34 | + * The conversation that this response belongs to. Items from this conversation are |
| 35 | + * prepended to `input_items` for this response request. Input items and output |
| 36 | + * items from this response are automatically added to this conversation after this |
| 37 | + * response completes. |
| 38 | + */ |
| 39 | + conversation?: string | ResponsesAPI.ResponseConversationParam | null; |
| 40 | + |
| 41 | + /** |
| 42 | + * Text, image, or file inputs to the model, used to generate a response |
| 43 | + */ |
| 44 | + input?: string | Array<ResponsesAPI.ResponseInputItem> | null; |
| 45 | + |
| 46 | + /** |
| 47 | + * A system (or developer) message inserted into the model's context. When used |
| 48 | + * along with `previous_response_id`, the instructions from a previous response |
| 49 | + * will not be carried over to the next response. This makes it simple to swap out |
| 50 | + * system (or developer) messages in new responses. |
| 51 | + */ |
| 52 | + instructions?: string | null; |
| 53 | + |
| 54 | + /** |
| 55 | + * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a |
| 56 | + * wide range of models with different capabilities, performance characteristics, |
| 57 | + * and price points. Refer to the |
| 58 | + * [model guide](https://platform.openai.com/docs/models) to browse and compare |
| 59 | + * available models. |
| 60 | + */ |
| 61 | + model?: string | null; |
| 62 | + |
| 63 | + /** |
| 64 | + * Whether to allow the model to run tool calls in parallel. |
| 65 | + */ |
| 66 | + parallel_tool_calls?: boolean | null; |
| 67 | + |
| 68 | + /** |
| 69 | + * The unique ID of the previous response to the model. Use this to create |
| 70 | + * multi-turn conversations. Learn more about |
| 71 | + * [conversation state](https://platform.openai.com/docs/guides/conversation-state). |
| 72 | + * Cannot be used in conjunction with `conversation`. |
| 73 | + */ |
| 74 | + previous_response_id?: string | null; |
| 75 | + |
| 76 | + /** |
| 77 | + * **gpt-5 and o-series models only** Configuration options for |
| 78 | + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). |
| 79 | + */ |
| 80 | + reasoning?: Shared.Reasoning | null; |
| 81 | + |
| 82 | + /** |
| 83 | + * Configuration options for a text response from the model. Can be plain text or |
| 84 | + * structured JSON data. Learn more: |
| 85 | + * |
| 86 | + * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text) |
| 87 | + * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs) |
| 88 | + */ |
| 89 | + text?: InputTokenCountParams.Text | null; |
| 90 | + |
| 91 | + /** |
| 92 | + * How the model should select which tool (or tools) to use when generating a |
| 93 | + * response. See the `tools` parameter to see how to specify which tools the model |
| 94 | + * can call. |
| 95 | + */ |
| 96 | + tool_choice?: |
| 97 | + | ResponsesAPI.ToolChoiceOptions |
| 98 | + | ResponsesAPI.ToolChoiceAllowed |
| 99 | + | ResponsesAPI.ToolChoiceTypes |
| 100 | + | ResponsesAPI.ToolChoiceFunction |
| 101 | + | ResponsesAPI.ToolChoiceMcp |
| 102 | + | ResponsesAPI.ToolChoiceCustom |
| 103 | + | null; |
| 104 | + |
| 105 | + /** |
| 106 | + * An array of tools the model may call while generating a response. You can |
| 107 | + * specify which tool to use by setting the `tool_choice` parameter. |
| 108 | + */ |
| 109 | + tools?: Array<ResponsesAPI.Tool> | null; |
| 110 | + |
| 111 | + /** |
| 112 | + * The truncation strategy to use for the model response. - `auto`: If the input to |
| 113 | + * this Response exceeds the model's context window size, the model will truncate |
| 114 | + * the response to fit the context window by dropping items from the beginning of |
| 115 | + * the conversation. - `disabled` (default): If the input size will exceed the |
| 116 | + * context window size for a model, the request will fail with a 400 error. |
| 117 | + */ |
| 118 | + truncation?: 'auto' | 'disabled'; |
| 119 | +} |
| 120 | + |
| 121 | +export namespace InputTokenCountParams { |
| 122 | + /** |
| 123 | + * Configuration options for a text response from the model. Can be plain text or |
| 124 | + * structured JSON data. Learn more: |
| 125 | + * |
| 126 | + * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text) |
| 127 | + * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs) |
| 128 | + */ |
| 129 | + export interface Text { |
| 130 | + /** |
| 131 | + * An object specifying the format that the model must output. |
| 132 | + * |
| 133 | + * Configuring `{ "type": "json_schema" }` enables Structured Outputs, which |
| 134 | + * ensures the model will match your supplied JSON schema. Learn more in the |
| 135 | + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). |
| 136 | + * |
| 137 | + * The default format is `{ "type": "text" }` with no additional options. |
| 138 | + * |
| 139 | + * **Not recommended for gpt-4o and newer models:** |
| 140 | + * |
| 141 | + * Setting to `{ "type": "json_object" }` enables the older JSON mode, which |
| 142 | + * ensures the message the model generates is valid JSON. Using `json_schema` is |
| 143 | + * preferred for models that support it. |
| 144 | + */ |
| 145 | + format?: ResponsesAPI.ResponseFormatTextConfig; |
| 146 | + |
| 147 | + /** |
| 148 | + * Constrains the verbosity of the model's response. Lower values will result in |
| 149 | + * more concise responses, while higher values will result in more verbose |
| 150 | + * responses. Currently supported values are `low`, `medium`, and `high`. |
| 151 | + */ |
| 152 | + verbosity?: 'low' | 'medium' | 'high' | null; |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +export declare namespace InputTokens { |
| 157 | + export { |
| 158 | + type InputTokenCountResponse as InputTokenCountResponse, |
| 159 | + type InputTokenCountParams as InputTokenCountParams, |
| 160 | + }; |
| 161 | +} |
0 commit comments