import { OpenAI, Raw } from '@vscode/prompt-tsx'; import { TelemetryData } from '../../telemetry/common/telemetryData'; import { ThinkingData, ThinkingDataInMessage } from '../../thinking/common/thinking'; import { ICopilotReference, RequestId } from './fetch'; /** * How the logprobs field looks in the OpenAI API chunks. */ export interface APILogprobs { text_offset: number[]; token_logprobs: number[]; top_logprobs?: { [key: string]: number; }[]; tokens: string[]; } /** * Usage statistics for the completion request. */ export interface APIUsage { /** * Number of tokens in the prompt. */ prompt_tokens: number; /** * Number of tokens in the generated completion. */ completion_tokens: number; /** * Total number of tokens used in the request (prompt + completion). */ total_tokens: number; /** * Breakdown of tokens used in the prompt. */ prompt_tokens_details?: { cached_tokens: number; cache_creation_input_tokens?: number; /** * Anthropic-specific: per-TTL breakdown of cache-creation (write) input * tokens. Mirrors Anthropic's `usage.cache_creation` object verbatim. * Only populated for Anthropic Messages API responses where the server * reports the split; absent for all other providers and for older * Anthropic responses that don't include the breakdown. */ anthropic_cache_creation?: { /** Cache-creation tokens written with the 1h (extended) TTL — billed at 2x base input rate. */ ephemeral_1h_input_tokens?: number; /** Cache-creation tokens written with the default 5m TTL — billed at 1.25x base input rate. */ ephemeral_5m_input_tokens?: number; }; }; /** * Breakdown of tokens used in a completion. * * @remark it's an optional field because Copilot Proxy returns this information but not CAPI as of 18 Jun 2025 */ completion_tokens_details?: { /** * Tokens generated by the model for reasoning. */ reasoning_tokens: number; /** * When using Predicted Outputs, the number of tokens in the prediction that appeared in the completion. */ accepted_prediction_tokens: number; /** * When using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion. * However, like reasoning tokens, these tokens are still counted in the total completion tokens for purposes of billing, * output, and context window limits. */ rejected_prediction_tokens: number; }; /** * Copilot billing usage for this request, returned by CAPI. */ copilot_usage?: { total_nano_aiu: number; }; } export declare function isApiUsage(obj: unknown): obj is APIUsage; /** * Converts a nano-AIU value from copilot_usage to a credit number. * Returns `undefined` when the value is missing or negative. */ export declare function nanoAiuToCredits(nanoAiu: number | undefined): number | undefined; export interface APIJsonData { text: string; tokens: readonly string[]; logprobs?: APILogprobs; } export interface APIErrorResponse { code: number; message: string; metadata?: Record; } export declare const openAIContextManagementCompactionType = "compaction"; export declare const modelsWithoutResponsesContextManagement: Set; export interface OpenAIContextManagement { type: typeof openAIContextManagementCompactionType; compact_threshold: number; } export interface OpenAIContextManagementResponse { encrypted_content: string; type: typeof openAIContextManagementCompactionType; id: string; } export declare enum ChatRole { System = "system", User = "user", Assistant = "assistant", Function = "function", Tool = "tool" } export type CAPIChatMessage = OpenAI.ChatMessage & { /** * CAPI references used in this message. */ copilot_references?: ICopilotReference[]; /** * CAPI confirmations used in this message. */ copilot_confirmations?: { state: string; confirmation: any; }[]; copilot_cache_control?: { 'type': 'ephemeral'; }; } & ThinkingDataInMessage; export declare function getCAPITextPart(content: string | OpenAI.ChatCompletionContentPart[] | OpenAI.ChatCompletionContentPart): string; export type RawMessageConversionCallback = (message: CAPIChatMessage, thinkingData?: ThinkingData) => void; /** * Converts a raw TSX chat message to CAPI's format. * * **Extra:** the raw message can have `copilot_references` and * `copilot_confirmations` properties, which are copied to the CAPI message. */ export declare function rawMessageToCAPI(message: Raw.ChatMessage, callback?: RawMessageConversionCallback): CAPIChatMessage; export declare function rawMessageToCAPI(message: Raw.ChatMessage[], callback?: RawMessageConversionCallback): CAPIChatMessage[]; export declare enum FinishedCompletionReason { /** * Reason generated by the server. See https://platform.openai.com/docs/guides/gpt/chat-completions-api */ Stop = "stop", /** * Reason generated by the server. See https://platform.openai.com/docs/guides/gpt/chat-completions-api */ Length = "length", /** * Reason generated by the server. See https://platform.openai.com/docs/guides/gpt/chat-completions-api */ FunctionCall = "function_call", /** * Reason generated by the server. See https://platform.openai.com/docs/guides/gpt/chat-completions-api */ ToolCalls = "tool_calls", /** * Reason generated by the server. See https://platform.openai.com/docs/guides/gpt/chat-completions-api */ ContentFilter = "content_filter", /** * Reason generated by the server. The model itself declined, as opposed to {@link ContentFilter} * where a separate system blocked the response. */ Refusal = "refusal", /** * Reason generated by the server (CAPI). Happens when the stream cannot be completed and the server must terminate the response. */ ServerError = "error", /** * Reason generated by the client when the finish callback asked for processing to stop. */ ClientTrimmed = "client-trimmed", /** * Reason generated by the client when we never received a finish_reason for this particular completion (indicates a server-side bug) */ ClientIterationDone = "Iteration Done", /** * Reason generated by the client when we never received a finish_reason for this particular completion (indicates a server-side bug) */ ClientDone = "DONE" } export interface IToolCall { index: number; id?: string; function?: { name: string; arguments: string; }; } /** * Contains the possible reasons a response can be filtered */ export declare enum FilterReason { /** * Content deemed to be hateful */ Hate = "hate", /** * Content deemed to cause self harm */ SelfHarm = "self_harm", /** * Content deemed to be sexual in nature */ Sexual = "sexual", /** * Content deemed to be violent in nature */ Violence = "violence", /** * Content contains copyrighted material */ Copyright = "snippy", /** * The prompt was filtered, the reason was not provided */ Prompt = "prompt" } export interface ChatCompletion { message: Raw.ChatMessage; choiceIndex: number; requestId: RequestId; tokens: readonly string[]; usage: APIUsage | undefined; model: string; blockFinished: boolean; finishReason: FinishedCompletionReason; filterReason?: FilterReason; telemetryData: TelemetryData; error?: APIErrorResponse; } export interface ChoiceLogProbs { content: ChoiceLogProbsContent[]; } export interface TokenLogProb { bytes: number[]; token: string; logprob: number; } export interface ChoiceLogProbsContent extends TokenLogProb { top_logprobs: TokenLogProb[]; } //# sourceMappingURL=openai.d.ts.map