Skip to content

DeepSeek Plugin

The @genkit-ai/compat-oai package includes a pre-configured plugin for DeepSeek models.

Terminal window
npm install @genkit-ai/compat-oai

To use this plugin, import deepSeek and specify it when you initialize Genkit.

import { genkit } from 'genkit';
import { deepSeek } from '@genkit-ai/compat-oai/deepseek';
export const ai = genkit({
plugins: [deepSeek()],
});

You must provide an API key from DeepSeek. You can get an API key from your DeepSeek account settings.

Configure the plugin to use your API key by doing one of the following:

  • Set the DEEPSEEK_API_KEY environment variable to your API key.

  • Specify the API key when you initialize the plugin:

    deepSeek({ apiKey: yourKey });

As always, avoid embedding API keys directly in your code.

Use the deepSeek.model() helper to reference a DeepSeek model.

import { genkit, z } from 'genkit';
import { deepSeek } from '@genkit-ai/compat-oai/deepseek';
const ai = genkit({
plugins: [deepSeek({ apiKey: process.env.DEEPSEEK_API_KEY })],
});
export const deepseekFlow = ai.defineFlow(
{
name: 'deepseekFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (subject) => {
// Reference a model
const deepseekChat = deepSeek.model('deepseek-chat');
// Use it in a generate call
const llmResponse = await ai.generate({
model: deepseekChat,
prompt: `Tell me something about ${subject}.`,
});
return llmResponse.text();
},
);

You can also pass model-specific configuration:

const llmResponse = await ai.generate({
model: deepSeek.model('deepseek-chat'),
prompt: 'Tell me something about deep learning.',
config: {
temperature: 0.8,
maxTokens: 1024,
},
});

You can pass configuration options that are not defined in the plugin’s custom config schema. This permits you to access new models and features without having to update your Genkit version.

import { genkit } from 'genkit';
import { deepSeek } from '@genkit-ai/compat-oai/deepSeek';
const ai = genkit({
plugins: [deepSeek()],
});
const llmResponse = await ai.generate({
prompt: `Tell me a cool story`,
model: deepSeek.model('deepseek-new'), // hypothetical new model
config: {
new_feature_parameter: ... // hypothetical config needed for new model
},
});

Genkit passes this configuration as-is to the DeepSeek API giving you access to the new model features. Note that the field name and types are not validated by Genkit and should match the DeepSeek API specification to work.