Skip to content

DeepSeek plugin

DeepSeek models run through the OpenAI-compatible OpenAI plugin in genkit-openai.

Terminal window
uv add genkit-openai

Point OpenAI at DeepSeek’s API endpoint and pass your API key from DeepSeek Platform:

import os
from genkit import Genkit
from genkit_openai import OpenAI
ai = Genkit(
plugins=[
OpenAI(
base_url='https://api.deepseek.com/v1',
api_key=os.environ['DEEPSEEK_API_KEY'],
),
],
)

For multi-tenant apps, override the key on individual calls with context={'secrets': {'api_key': tenant_key}}.

Reference DeepSeek models with the 'openai/<model-id>' prefix:

@ai.flow()
async def deepseek_flow(subject: str) -> str:
response = await ai.generate(
model='openai/deepseek-v4-flash',
prompt=f'Explain the core mechanism behind {subject}.',
)
return response.text

Available models:

  • deepseek-v4-flash: Fast, low-cost model
  • deepseek-v4-pro: Flagship model with the strongest reasoning and agent capabilities

Both support thinking and non-thinking modes. Thinking is on by default.

Prefer the explicit V4 model IDs over legacy deepseek-chat and deepseek-reasoner aliases.

DeepSeek returns its thinking as reasoning_content. Genkit maps it to reasoning parts on the response message, next to the answer text:

@ai.flow()
async def reasoning_flow(problem: str) -> str:
response = await ai.generate(
model='openai/deepseek-v4-pro',
prompt=f'Solve this problem step by step: {problem}',
)
reasoning = ''.join(p.reasoning or '' for p in response.message.content)
print(reasoning)
# => Let me work through this step by step...
return response.text

Genkit drops reasoning parts when it replays history to DeepSeek on later turns.

from pydantic import BaseModel, Field
class WeatherInput(BaseModel):
location: str = Field(description='City name')
@ai.tool()
async def get_weather(input: WeatherInput) -> str:
"""Get the current weather for a location."""
return f'22°C and clear in {input.location}'
@ai.flow()
async def weather_flow(location: str) -> str:
response = await ai.generate(
model='openai/deepseek-v4-flash',
prompt=f'What is the weather in {location}?',
tools=[get_weather],
tool_choice='auto',
)
return response.text
from genkit import FlowContext
@ai.flow()
async def streaming_flow(topic: str, ctx: FlowContext[str]) -> str:
stream_response = ai.generate_stream(
model='openai/deepseek-v4-flash',
prompt=f'Write a concise technical overview of {topic}.',
)
async for chunk in stream_response.stream:
ctx.send_chunk(chunk.text)
return (await stream_response.response).text
@ai.flow()
async def chat_flow() -> str:
first = await ai.generate(
model='openai/deepseek-v4-flash',
system='You are a pragmatic database reliability engineer.',
prompt='I am migrating a PostgreSQL database with 2 TB of time-series tables.',
)
# first.messages carries the system prompt, the user turn, and the reply.
second = await ai.generate(
model='openai/deepseek-v4-flash',
messages=first.messages,
prompt='What partitioning strategy fits this size?',
)
return second.text

DeepSeek accepts response_format type json_object but not json_schema. For deepseek* model IDs, Genkit sends json_object and adds your schema to the prompt as a system message. response.output is a validated BookRecommendation instance.

from pydantic import BaseModel, Field
class BookRecommendation(BaseModel):
title: str = Field(description='Book title')
author: str = Field(description='Book author')
genre: str = Field(description='Primary genre')
summary: str = Field(description='Brief summary')
@ai.flow()
async def recommend_book(preferences: str) -> BookRecommendation:
response = await ai.generate(
model='openai/deepseek-v4-flash',
prompt=f'Recommend one book for someone interested in: {preferences}',
output_schema=BookRecommendation,
)
return response.output

Forwarding DeepSeek-specific parameters with extra

Section titled “Forwarding DeepSeek-specific parameters with extra”

OpenAIConfig rejects undeclared top-level keys. Pass DeepSeek-specific request fields inside extra. This turns thinking off for a quick answer:

from genkit_openai import OpenAIConfig
response = await ai.generate(
model='openai/deepseek-v4-flash',
prompt='Summarize the trade-offs of Raft vs. Multi-Paxos in two sentences.',
config=OpenAIConfig(
max_output_tokens=512,
extra={'thinking': {'type': 'disabled'}},
),
)

Genkit sends max_output_tokens as max_tokens and merges extra into the request body. Keys Genkit builds itself, such as messages, tools, and response_format, are rejected inside extra with INVALID_ARGUMENT.