Conversations
Send prompts and conversation history to DeepSeek Web with `@orcushq/deepseek`. Learn how to invoke models and manage conversation context.
DeepSeekWeb.invoke() and DeepSeekWeb.stream() accept either a string prompt or an array of messages. The SDK converts message arrays into the prompt format accepted by DeepSeek Web.
Sending a Conversation
Create a DeepSeekWeb client with your model and credentials, then call invoke() with your prompt. DeepSeek Web requires both a session cookie and an authorization value. Unlike the Gemini package, DeepSeek does not provide a guest mode.
import 'dotenv/config'import { DeepSeekWeb } from '@orcushq/deepseek' const model = new DeepSeekWeb({ model: 'deepseek-v3', dsSessionId: process.env.DEEPSEEK_SESSION_ID ?? '', authorization: process.env.DEEPSEEK_AUTHORIZATION ?? '',}) const response = await model.invoke('What is Apple?') console.log(response.content)console.log(response.finishReason)console.log(response.metadata.modelId)Set DEEPSEEK_SESSION_ID and DEEPSEEK_AUTHORIZATION in your .env file before running the example. The SDK does not load environment variables automatically; dotenv/config loads them for this example.
invoke() returns a response object. Use response.content for the generated text, response.finishReason for the completion reason, and response.metadata.modelId for the model ID resolved by the SDK.
Sending Conversation History
Pass an array of messages in chronological order when you want to include earlier context. Include previous user messages and assistant replies yourself. The SDK normalizes these messages into a single prompt before sending the request.
const response = await model.invoke([ { role: 'user', content: 'My name is Vikas.' }, { role: 'assistant', content: 'Nice to meet you!' }, { role: 'user', content: 'What is my name?' },]) console.log(response.content)Supported message roles
DeepSeekMessage supports four roles: user, assistant, system, and tool. Each message contains a role and content. The SDK converts these roles into text prefixes as part of prompt normalization; they are not sent as separate native chat messages.
- `user` - Supplies the user prompt.
- `assistant` - Includes a previous assistant reply.
- `system` - Adds instructions to the prompt.
- `tool` - Includes a tool result in the prompt.
const response = await model.invoke([ { role: 'system', content: 'Answer in one short sentence.', }, { role: 'user', content: 'Explain what an API is.', },]) console.log(response.content)Managing conversation history
Keep conversation history in your application and pass the relevant messages to each call. A chatSessionId identifies the conversation but does not, by itself, guarantee that previous messages are restored. When continuing a conversation from a fresh client without a parent message anchor, provide the relevant history explicitly.
const history = [ { role: 'user', content: 'My name is Vikas.' }, { role: 'assistant', content: 'Nice to meet you!' },] as const const response = await model.invoke([ ...history, { role: 'user', content: 'What is my name?' },]) console.log(response.content)Conversation identifiers
Use chatSessionId to identify a DeepSeek conversation and parentMessageId to identify the message from which the next turn continues. These are per-call options, not authentication credentials. When chatSessionId is omitted, the SDK creates a conversation through DeepSeek Web and returns its server-issued ID in response.metadata.chatSessionId. To continue an existing conversation from another client, pass both identifiers. The SDK does not automatically restore earlier messages merely because you reuse a conversation ID.
const first = await model.invoke('My name is Vikas.') // Create another client for the same authenticated account.const otherModel = new DeepSeekWeb({ model: 'deepseek-v3', dsSessionId: process.env.DEEPSEEK_SESSION_ID ?? '', authorization: process.env.DEEPSEEK_AUTHORIZATION ?? '',}) // Continue from the identifiers returned by the first response.const second = await otherModel.invoke( 'What is my name?', { chatSessionId: first.metadata.chatSessionId, parentMessageId: first.metadata.parentMessageId, },) console.log(second.content)withConfig() does not copy conversation state
`withConfig()` creates a client with merged configuration, but the derived client does not carry `chatSessionId` or `parentMessageId`. Supply the conversation identifiers explicitly when continuing a conversation with the derived client.
Chat session IDs
DeepSeek Web issues the chat session ID when a new conversation is created. The SDK exposes this server-issued ID as response.metadata.chatSessionId. You can reuse it through the chatSessionId invocation option. Do not generate a random UUID and assume it is a valid DeepSeek chat session ID. To continue from a specific message using another client, also provide the corresponding parentMessageId. The chat session ID identifies the conversation; it does not, by itself, restore earlier message history.
const first = await model.invoke('My name is Vikas.') console.log('Chat session ID:', first.metadata.chatSessionId) // Continue the conversation using the same client.// Its conversation state is carried forward automatically.const second = await model.invoke('What is my name?') console.log(second.content) // To continue from another client, pass both identifiers:// {// chatSessionId: first.metadata.chatSessionId,// parentMessageId: first.metadata.parentMessageId,// }