# ChatDeepSeek

> **Class** in `@langchain/deepseek`

📖 [View in docs](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek)

Deepseek chat model integration.

The Deepseek API is compatible to the OpenAI API with some limitations.

Setup:
Install `@langchain/deepseek` and set an environment variable named `DEEPSEEK_API_KEY`.

```bash
npm install @langchain/deepseek
export DEEPSEEK_API_KEY="your-api-key"
```

## [Constructor args](https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html#constructor)

## [Runtime args](https://api.js.langchain.com/interfaces/_langchain_deepseek.ChatDeepSeekCallOptions.html)

Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:

```typescript
// When calling `.withConfig`, call options should be passed via the first argument
const llmWithArgsBound = llm.withConfig({
  stop: ["\n"],
  tools: [...],
});

// When calling `.bindTools`, call options should be passed via the second argument
const llmWithTools = llm.bindTools(
  [...],
  {
    tool_choice: "auto",
  }
);
```

## Examples

<details open>
<summary><strong>Instantiate</strong></summary>

```typescript
import { ChatDeepSeek } from '@langchain/deepseek';

const llm = new ChatDeepSeek({
  model: "deepseek-reasoner",
  temperature: 0,
  // other params...
});
```
</details>

<br />

<details>
<summary><strong>Invoking</strong></summary>

```typescript
const input = `Translate "I love programming" into French.`;

// Models also accept a list of chat messages or a formatted prompt
const result = await llm.invoke(input);
console.log(result);
```

```txt
AIMessage {
  "content": "The French translation of \"I love programming\" is \"J'aime programmer\". In this sentence, \"J'aime\" is the first person singular conjugation of the French verb \"aimer\" which means \"to love\", and \"programmer\" is the French infinitive for \"to program\". I hope this helps! Let me know if you have any other questions.",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "tokenUsage": {
      "completionTokens": 82,
      "promptTokens": 20,
      "totalTokens": 102
    },
    "finish_reason": "stop"
  },
  "tool_calls": [],
  "invalid_tool_calls": []
}
```
</details>

<br />

<details>
<summary><strong>Streaming Chunks</strong></summary>

```typescript
for await (const chunk of await llm.stream(input)) {
  console.log(chunk);
}
```

```txt
AIMessageChunk {
  "content": "",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
AIMessageChunk {
  "content": "The",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
AIMessageChunk {
  "content": " French",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
AIMessageChunk {
  "content": " translation",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
AIMessageChunk {
  "content": " of",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
AIMessageChunk {
  "content": " \"",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
AIMessageChunk {
  "content": "I",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
AIMessageChunk {
  "content": " love",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
...
AIMessageChunk {
  "content": ".",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": null
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
AIMessageChunk {
  "content": "",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": "stop"
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
```
</details>

<br />

<details>
<summary><strong>Aggregate Streamed Chunks</strong></summary>

```typescript
import { AIMessageChunk } from '@langchain/core/messages';
import { concat } from '@langchain/core/utils/stream';

const stream = await llm.stream(input);
let full: AIMessageChunk | undefined;
for await (const chunk of stream) {
  full = !full ? chunk : concat(full, chunk);
}
console.log(full);
```

```txt
AIMessageChunk {
  "content": "The French translation of \"I love programming\" is \"J'aime programmer\". In this sentence, \"J'aime\" is the first person singular conjugation of the French verb \"aimer\" which means \"to love\", and \"programmer\" is the French infinitive for \"to program\". I hope this helps! Let me know if you have any other questions.",
  "additional_kwargs": {
    "reasoning_content": "...",
  },
  "response_metadata": {
    "finishReason": "stop"
  },
  "tool_calls": [],
  "tool_call_chunks": [],
  "invalid_tool_calls": []
}
```
</details>

<br />

<details>
<summary><strong>Bind tools</strong></summary>

```typescript
import { z } from 'zod';

const llmForToolCalling = new ChatDeepSeek({
  model: "deepseek-chat",
  temperature: 0,
  // other params...
});

const GetWeather = {
  name: "GetWeather",
  description: "Get the current weather in a given location",
  schema: z.object({
    location: z.string().describe("The city and state, e.g. San Francisco, CA")
  }),
}

const GetPopulation = {
  name: "GetPopulation",
  description: "Get the current population in a given location",
  schema: z.object({
    location: z.string().describe("The city and state, e.g. San Francisco, CA")
  }),
}

const llmWithTools = llmForToolCalling.bindTools([GetWeather, GetPopulation]);
const aiMsg = await llmWithTools.invoke(
  "Which city is hotter today and which is bigger: LA or NY?"
);
console.log(aiMsg.tool_calls);
```

```txt
[
  {
    name: 'GetWeather',
    args: { location: 'Los Angeles, CA' },
    type: 'tool_call',
    id: 'call_cd34'
  },
  {
    name: 'GetWeather',
    args: { location: 'New York, NY' },
    type: 'tool_call',
    id: 'call_68rf'
  },
  {
    name: 'GetPopulation',
    args: { location: 'Los Angeles, CA' },
    type: 'tool_call',
    id: 'call_f81z'
  },
  {
    name: 'GetPopulation',
    args: { location: 'New York, NY' },
    type: 'tool_call',
    id: 'call_8byt'
  }
]
```
</details>

<br />

<details>
<summary><strong>Structured Output</strong></summary>

```typescript
import { z } from 'zod';

const Joke = z.object({
  setup: z.string().describe("The setup of the joke"),
  punchline: z.string().describe("The punchline to the joke"),
  rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
}).describe('Joke to tell user.');

const structuredLlm = llmForToolCalling.withStructuredOutput(Joke, { name: "Joke" });
const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
console.log(jokeResult);
```

```txt
{
  setup: "Why don't cats play poker in the wild?",
  punchline: 'Because there are too many cheetahs.'
}
```
</details>

<br />

## Signature

```javascript
class ChatDeepSeek
```

## Extends

- `ChatOpenAICompletions<ChatDeepSeekCallOptions>`

## Constructors

- [`constructor()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/constructor)

## Properties

- `__includeRawResponse`
- `apiKey`
- `audio`
- `cache`
- `callbacks`
- `caller`
- `defaultOptions`
- `disableStreaming`
- `frequencyPenalty`
- `lc_kwargs`
- `lc_namespace`
- `lc_runnable`
- `lc_serializable`
- `logitBias`
- `logprobs`
- `maxTokens`
- `metadata`
- `modalities`
- `model`
- `modelKwargs`
- `n`
- `name`
- `organization`
- `outputVersion`
- `ParsedCallOptions`
- `presencePenalty`
- `promptCacheKey`
- `promptCacheRetention`
- `reasoning`
- `service_tier`
- `stop`
- `stopSequences`
- `streaming`
- `streamUsage`
- `supportsStrictToolCalling`
- `tags`
- `temperature`
- `timeout`
- `topLogprobs`
- `topP`
- `user`
- `verbose`
- `verbosity`
- `zdrEnabled`
- `callKeys`
- `lc_aliases`
- `lc_attributes`
- `lc_id`
- `lc_secrets`
- `lc_serializable_keys`
- `profile`

## Methods

- [`_addVersion()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_addVersion)
- [`_batchWithConfig()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_batchWithConfig)
- [`_callWithConfig()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_callWithConfig)
- [`_combineCallOptions()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_combineCallOptions)
- [`_convertChatOpenAIToolToCompletionsTool()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_convertChatOpenAIToolToCompletionsTool)
- [`_convertCompletionsDeltaToBaseMessageChunk()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_convertCompletionsDeltaToBaseMessageChunk)
- [`_convertCompletionsMessageToBaseMessage()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_convertCompletionsMessageToBaseMessage)
- [`_generate()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_generate)
- [`_generateCached()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_generateCached)
- [`_getOptionsList()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_getOptionsList)
- [`_getSerializedCacheKeyParametersForCall()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_getSerializedCacheKeyParametersForCall)
- [`_llmType()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_llmType)
- [`_modelType()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_modelType)
- [`_separateRunnableConfigFromCallOptions()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_separateRunnableConfigFromCallOptions)
- [`_separateRunnableConfigFromCallOptionsCompat()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_separateRunnableConfigFromCallOptionsCompat)
- [`_streamIterator()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_streamIterator)
- [`_streamLog()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_streamLog)
- [`_streamResponseChunks()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_streamResponseChunks)
- [`_transformStreamWithConfig()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_transformStreamWithConfig)
- [`assign()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/assign)
- [`asTool()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/asTool)
- [`batch()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/batch)
- [`bindTools()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/bindTools)
- [`completionWithRetry()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/completionWithRetry)
- [`generate()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/generate)
- [`generatePrompt()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/generatePrompt)
- [`getGraph()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/getGraph)
- [`getLsParams()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/getLsParams)
- [`getName()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/getName)
- [`getNumTokens()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/getNumTokens)
- [`getNumTokensFromMessages()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/getNumTokensFromMessages)
- [`identifyingParams()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/identifyingParams)
- [`invoke()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/invoke)
- [`moderateContent()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/moderateContent)
- [`pick()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/pick)
- [`pipe()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/pipe)
- [`serialize()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/serialize)
- [`stream()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/stream)
- [`streamEvents()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/streamEvents)
- [`streamLog()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/streamLog)
- [`toJSON()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/toJSON)
- [`toJSONNotImplemented()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/toJSONNotImplemented)
- [`transform()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/transform)
- [`withConfig()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/withConfig)
- [`withFallbacks()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/withFallbacks)
- [`withListeners()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/withListeners)
- [`withRetry()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/withRetry)
- [`withStructuredOutput()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/withStructuredOutput)
- [`_convertInputToPromptValue()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/_convertInputToPromptValue)
- [`deserialize()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/deserialize)
- [`isRunnable()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/isRunnable)
- [`lc_name()`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek/lc_name)

---

[View source on GitHub](https://github.com/langchain-ai/langchainjs/blob/a596d3f7395c0ab27357aa0cd30bafb2d5d967c1/libs/providers/langchain-deepseek/src/chat_models.ts#L411)