How to Integrate DeepSeek AI in ASP.NET Core Web API (Step-by-Step Guide)
![]() |
Vivek Jaiswal |
92 |
{{e.like}} |
{{e.dislike}} |
Introduction
If you’re a .NET developer exploring AI, this guide is for you. In this tutorial, you’ll learn how to integrate DeepSeek AI into an ASP.NET Core Web API using the OpenRouter API.
By the end, you’ll be able to send prompts (like “Write a C# Hello World program”) and get intelligent AI-powered responses directly from your backend.
This is perfect for building:
-
AI-powered chatbots
-
Intelligent coding assistants
-
Natural language processing apps
๐ Why Use DeepSeek with OpenRouter?
-
Free testing key available via OpenRouter (great for experimenting).
-
Multiple models support, including
deepseek/deepseek-chat
. -
Seamless integration with .NET using
HttpClientFactory
. -
Clean & secure configuration via
appsettings.json
.
๐ Project Setup
We’ll create a simple ASP.NET Core Web API project that communicates with DeepSeek via OpenRouter.
1๏ธโฃ Add Configuration in appsettings.json
Replace "Your-Key"
with your OpenRouter API key. (You can start with a free key for testing.)
2๏ธโฃ Configure HttpClient in Program.cs
Here we registered an HttpClient
named OpenRouter that automatically adds headers for every request.
3๏ธโฃ Create ChatController.cs
This controller exposes an endpoint:
-
POST /api/chat/chat
-
Accepts a JSON body like:
-
Returns DeepSeek AI’s response.
๐งช Testing the API
-
Run your project.
-
Open Swagger (
/swagger
) or use Postman. -
Send a request to:
With body:
โ You’ll get a JSON response from DeepSeek AI!
โ Frequently Asked Questions (FAQ)
๐น 1. Is DeepSeek AI free to use?
Yes, you can start with a free testing API key via OpenRouter.
๐น 2. Can I use DeepSeek AI for production apps?
Yes, but for production you should use a paid API key with higher rate limits.
๐น 3. What kind of apps can I build with DeepSeek AI?
-
Chatbots
-
Document summarizers
-
Code assistants
-
Question-answering systems
๐น 4. How is this different from OpenAI GPT integration?
DeepSeek works via OpenRouter API, just like OpenAI models, but it’s optimized for efficient responses and often more cost-effective.
๐ฏ Conclusion
In this tutorial, we integrated DeepSeek AI into an ASP.NET Core Web API using OpenRouter.
-
We set up
appsettings.json
for API keys. -
Configured
HttpClientFactory
for secure API calls. -
Built a
ChatController
to send prompts and receive AI responses.
Now you can extend this project by:
-
Saving chat history in a database.
-
Building a frontend (React/Angular/Blazor) to consume your API.
-
Using more advanced DeepSeek models for specialized tasks.
๐ Related Resources
๐ก Pro Tip: Start with the free API key for testing, and when moving to production, keep your API keys secure using User Secrets or Environment Variables.
Comments
![]() |
|
Follow up comments |
{{e.Name}} {{e.Comments}} |
{{e.days}} | |
|
||
|
{{r.Name}} {{r.Comments}} |
{{r.days}} | |
|