## Create Completion `client.chat.createCompletion(ChatCreateCompletionParamsbody, RequestOptionsoptions?): ChatCreateCompletionResponse` **post** `/chat/completions` Create Chat Completion ### Parameters - `body: ChatCreateCompletionParams` - `messages: Array` - `ChatCompletionDeveloperMessageParam` Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, `developer` messages replace the previous `system` messages. - `content: string | Array` - `string` - `Array` - `text: string` - `type: "text"` - `"text"` - `role: "developer"` - `"developer"` - `name?: string` - `ChatCompletionSystemMessageParam` Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, use `developer` messages for this purpose instead. - `content: string | Array` - `string` - `Array` - `text: string` - `type: "text"` - `"text"` - `role: "system"` - `"system"` - `name?: string` - `ChatCompletionUserMessageParam` Messages sent by an end user, containing prompts or additional context information. - `content: string | Array` - `string` - `Array` - `ChatCompletionContentPartTextParam` Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation). - `text: string` - `type: "text"` - `"text"` - `ChatCompletionContentPartImageParam` Learn about [image inputs](https://platform.openai.com/docs/guides/vision). - `image_url: ImageURL` - `url: string` - `detail?: "auto" | "low" | "high"` - `"auto"` - `"low"` - `"high"` - `type: "image_url"` - `"image_url"` - `ChatCompletionContentPartInputAudioParam` Learn about [audio inputs](https://platform.openai.com/docs/guides/audio). - `input_audio: InputAudio` - `data: string` - `format: "wav" | "mp3"` - `"wav"` - `"mp3"` - `type: "input_audio"` - `"input_audio"` - `File` Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text generation. - `file: File` - `file_data?: string` - `file_id?: string` - `filename?: string` - `type: "file"` - `"file"` - `role: "user"` - `"user"` - `name?: string` - `ChatCompletionAssistantMessageParam` Messages sent by the model in response to user messages. - `role: "assistant"` - `"assistant"` - `audio?: Audio | null` Data about a previous audio response from the model. [Learn more](https://platform.openai.com/docs/guides/audio). - `id: string` - `content?: string | Array | null` - `string` - `Array` - `ChatCompletionContentPartTextParam` Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation). - `text: string` - `type: "text"` - `"text"` - `ChatCompletionContentPartRefusalParam` - `refusal: string` - `type: "refusal"` - `"refusal"` - `function_call?: FunctionCall | null` Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. - `arguments: string` - `name: string` - `name?: string` - `refusal?: string | null` - `tool_calls?: Array` - `ChatCompletionMessageFunctionToolCallParam` A call to a function tool created by the model. - `id: string` - `function: Function` The function that the model called. - `arguments: string` - `name: string` - `type: "function"` - `"function"` - `ChatCompletionMessageCustomToolCallParam` A call to a custom tool created by the model. - `id: string` - `custom: Custom` The custom tool that the model called. - `input: string` - `name: string` - `type: "custom"` - `"custom"` - `ChatCompletionToolMessageParam` - `content: string | Array` - `string` - `Array` - `text: string` - `type: "text"` - `"text"` - `role: "tool"` - `"tool"` - `tool_call_id: string` - `ChatCompletionFunctionMessageParam` - `content: string | null` - `name: string` - `role: "function"` - `"function"` - `CustomChatCompletionMessageParam` Enables custom roles in the Chat Completion API. - `role: string` - `content?: string | Array` - `string` - `Array` - `ChatCompletionContentPartTextParam` Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation). - `text: string` - `type: "text"` - `"text"` - `ChatCompletionContentPartImageParam` Learn about [image inputs](https://platform.openai.com/docs/guides/vision). - `image_url: ImageURL` - `url: string` - `detail?: "auto" | "low" | "high"` - `"auto"` - `"low"` - `"high"` - `type: "image_url"` - `"image_url"` - `ChatCompletionContentPartInputAudioParam` Learn about [audio inputs](https://platform.openai.com/docs/guides/audio). - `input_audio: InputAudio` - `data: string` - `format: "wav" | "mp3"` - `"wav"` - `"mp3"` - `type: "input_audio"` - `"input_audio"` - `File` Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text generation. - `file: File` - `file_data?: string` - `file_id?: string` - `filename?: string` - `type: "file"` - `"file"` - `ChatCompletionContentPartAudioParam` - `audio_url: AudioURL` - `url: string` - `type: "audio_url"` - `"audio_url"` - `ChatCompletionContentPartVideoParam` - `type: "video_url"` - `"video_url"` - `video_url: VideoURL` - `url: string` - `ChatCompletionContentPartRefusalParam` - `refusal: string` - `type: "refusal"` - `"refusal"` - `CustomChatCompletionContentSimpleImageParam` A simpler version of the param that only accepts a plain image_url. This is supported by OpenAI API, although it is not documented. Example: { "image_url": "https://example.com/image.jpg" } - `image_url?: string | null` - `uuid?: string | null` - `ChatCompletionContentPartImageEmbedsParam` - `type: "image_embeds"` - `"image_embeds"` - `image_embeds?: string | Record | null` - `string` - `Record` - `uuid?: string | null` - `ChatCompletionContentPartAudioEmbedsParam` - `type: "audio_embeds"` - `"audio_embeds"` - `audio_embeds?: string | Record | null` - `string` - `Record` - `uuid?: string | null` - `CustomChatCompletionContentSimpleAudioParam` A simpler version of the param that only accepts a plain audio_url. Example: { "audio_url": "https://example.com/audio.mp3" } - `audio_url?: string | null` - `CustomChatCompletionContentSimpleVideoParam` A simpler version of the param that only accepts a plain audio_url. Example: { "video_url": "https://example.com/video.mp4" } - `uuid?: string | null` - `video_url?: string | null` - `string` - `CustomThinkCompletionContentParam` A Think Completion Content Param that accepts a plain text and a boolean. Example: { "thinking": "I am thinking about the answer", "closed": True, "type": "thinking" } - `thinking: string` - `type: "thinking"` - `"thinking"` - `closed?: boolean` - `name?: string` - `reasoning?: string | null` - `tool_call_id?: string | null` - `tool_calls?: Array | null` - `id: string` - `function: Function` The function that the model called. - `arguments: string` - `name: string` - `type: "function"` - `"function"` - `tools?: Array | null` - `function: Function` - `name: string` - `description?: string` - `parameters?: Record` - `strict?: boolean | null` - `type: "function"` - `"function"` - `Message` - `author: Author` - `role: "user" | "assistant" | "system" | 2 more` The role of a message author (mirrors `chat::Role`). - `"user"` - `"assistant"` - `"system"` - `"developer"` - `"tool"` - `name?: string | null` - `channel?: string | null` - `content?: Array` - `content_type?: string | null` - `recipient?: string | null` - `add_generation_prompt?: boolean` If true, the generation prompt will be added to the chat template. This is a parameter used by chat template in tokenizer config of the model. - `add_special_tokens?: boolean` If true, special tokens (e.g. BOS) will be added to the prompt on top of what is added by the chat template. For most models, the chat template takes care of adding the special tokens so this should be set to false (as is the default). - `allowed_token_ids?: Array | null` - `bad_words?: Array` - `cache_salt?: string | null` If specified, the prefix cache will be salted with the provided string to prevent an attacker to guess prompts in multi-user environments. The salt should be random, protected from access by 3rd parties, and long enough to be unpredictable (e.g., 43 characters base64-encoded, corresponding to 256 bit). - `chat_template?: string | null` A Jinja template to use for this conversion. As of transformers v4.44, default chat template is no longer allowed, so you must provide a chat template if the tokenizer does not define one. - `chat_template_kwargs?: Record | null` Additional keyword args to pass to the template renderer. Will be accessible by the chat template. - `continue_final_message?: boolean` If this is set, the chat will be formatted so that the final message in the chat is open-ended, without any EOS tokens. The model will continue this message rather than starting a new one. This allows you to "prefill" part of the model's response for it. Cannot be used at the same time as `add_generation_prompt`. - `documents?: Array> | null` A list of dicts representing documents that will be accessible to the model if it is performing RAG (retrieval-augmented generation). If the template does not support RAG, this argument will have no effect. We recommend that each document should be a dict containing "title" and "text" keys. - `echo?: boolean` If true, the new message will be prepended with the last message if they belong to the same role. - `frequency_penalty?: number | null` - `ignore_eos?: boolean` - `include_reasoning?: boolean` - `include_stop_str_in_output?: boolean` - `kv_transfer_params?: Record | null` KVTransfer parameters used for disaggregated serving. - `length_penalty?: number` - `logit_bias?: Record | null` - `logits_processors?: Array | null` A list of either qualified names of logits processors, or constructor objects, to apply when sampling. A constructor is a JSON object with a required 'qualname' field specifying the qualified name of the processor class/factory, and optional 'args' and 'kwargs' fields containing positional and keyword arguments. For example: {'qualname': 'my_module.MyLogitsProcessor', 'args': [1, 2], 'kwargs': {'param': 'value'}}. - `string` - `LogitsProcessorConstructor` - `qualname: string` - `args?: Array | null` - `kwargs?: Record | null` - `logprobs?: boolean | null` - `max_completion_tokens?: number | null` - `max_tokens?: number | null` - `min_p?: number | null` - `min_tokens?: number` - `mm_processor_kwargs?: Record | null` Additional kwargs to pass to the HF processor. - `model?: string | null` - `n?: number | null` - `parallel_tool_calls?: boolean | null` - `presence_penalty?: number | null` - `priority?: number` The priority of the request (lower means earlier handling; default: 0). Any priority other than 0 will raise an error if the served model does not use priority scheduling. - `prompt_logprobs?: number | null` - `reasoning_effort?: "low" | "medium" | "high" | null` - `"low"` - `"medium"` - `"high"` - `repetition_penalty?: number | null` - `request_id?: string` The request_id related to this request. If the caller does not set it, a random_uuid will be generated. This id is used through out the inference process and return in response. - `response_format?: ResponseFormat | StructuralTagResponseFormat | LegacyStructuralTagResponseFormat | null` - `ResponseFormat` - `type: "text" | "json_object" | "json_schema"` - `"text"` - `"json_object"` - `"json_schema"` - `json_schema?: JsonSchema | null` - `name: string` - `description?: string | null` - `schema?: Record | null` - `strict?: boolean | null` - `StructuralTagResponseFormat` - `format: unknown` - `type: "structural_tag"` - `"structural_tag"` - `LegacyStructuralTagResponseFormat` - `structures: Array` - `begin: string` - `end: string` - `schema?: Record | null` - `triggers: Array` - `type: "structural_tag"` - `"structural_tag"` - `return_token_ids?: boolean | null` If specified, the result will include token IDs alongside the generated text. In streaming mode, prompt_token_ids is included only in the first chunk, and token_ids contains the delta tokens for each chunk. This is useful for debugging or when you need to map generated text back to input tokens. - `return_tokens_as_token_ids?: boolean | null` If specified with 'logprobs', tokens are represented as strings of the form 'token_id:{token_id}' so that tokens that are not JSON-encodable can be identified. - `seed?: number | null` - `skip_special_tokens?: boolean` - `spaces_between_special_tokens?: boolean` - `stop?: string | Array | null` - `string` - `Array` - `stop_token_ids?: Array | null` - `stream?: boolean | null` - `stream_options?: StreamOptions | null` - `continuous_usage_stats?: boolean | null` - `include_usage?: boolean | null` - `structured_outputs?: StructuredOutputs | null` Additional kwargs for structured outputs - `_backend?: string | null` - `_backend_was_auto?: boolean` - `choice?: Array | null` - `disable_additional_properties?: boolean` - `disable_any_whitespace?: boolean` - `disable_fallback?: boolean` - `grammar?: string | null` - `json?: string | Record | null` - `string` - `Record` - `json_object?: boolean | null` - `regex?: string | null` - `structural_tag?: string | null` - `whitespace_pattern?: string | null` - `temperature?: number | null` - `tool_choice?: "none" | "auto" | "required" | ChatCompletionNamedToolChoiceParam | null` - `"none" | "auto" | "required"` - `"none"` - `"auto"` - `"required"` - `ChatCompletionNamedToolChoiceParam` - `function: Function` - `name: string` - `type?: "function"` - `"function"` - `tools?: Array | null` - `function: Function` - `name: string` - `description?: string | null` - `parameters?: Record | null` - `type?: "function"` - `"function"` - `top_k?: number | null` - `top_logprobs?: number | null` - `top_p?: number | null` - `truncate_prompt_tokens?: number | null` - `use_beam_search?: boolean` - `user?: string | null` - `vllm_xargs?: Record> | null` Additional request parameters with (list of) string or numeric values, used by custom extensions. - `string` - `number` - `Array` - `string` - `number` ### Returns - `ChatCreateCompletionResponse = unknown` ### Example ```typescript import Lightcone from '@tzafon/lightcone'; const client = new Lightcone({ apiKey: process.env['TZAFON_API_KEY'], // This is the default and can be omitted }); const response = await client.chat.createCompletion({ messages: [{ content: 'string', role: 'developer' }], }); console.log(response); ```