Skip to content

Ron015/Deepseek-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DeepSeek-api

A Python package for interacting with the DeepSeek AI chat API. This package provides a clean interface to interact with DeepSeek's chat model, with support for streaming responses, thinking process visibility, and web search capabilities.

Learn how to reverse engineer private api's !!

⚠️ Service Notice: DeepSeek API is currently experiencing high load. Work is in progress to integrate additional API providers. Please expect intermittent errors.

📝 Note: If you encounter any errors, please ensure you are using the latest version of this library. The DeepSeek API may change frequently, and updates are released to maintain compatibility.

✨ Features

  • 🔄 Auto Continue: Auto continue for long response
  • 🤔 Thinking Process: Optional visibility into the model's reasoning steps
  • 🔍 Web Search: Optional integration for up-to-date information
  • 💬 Session Management: Persistent chat sessions with conversation history
  • Efficient PoW: WebAssembly-based proof of work implementation
  • 🛡️ Error Handling: Comprehensive error handling with specific exceptions
  • 🧵 Thread Support: Parent message tracking for threaded conversations

📦 Installation

  1. Clone the repository:
git clone https://github.com/Ron015/Deepseek-api.git
cd Deepseek-api
  1. Install dependencies:
pip install -r requirements.txt

🔑 Authentication

To use this package, you need a DeepSeek auth token. Here's how to obtain it:

If you know how to use chrome devtools, simply run this snipped in the console:

JSON.parse(localStorage.getItem("userToken")).value

Method 1: From LocalStorage (Recommended)

image
  1. Visit chat.deepseek.com
  2. Log in to your account
  3. Open browser developer tools (F12 or right-click > Inspect)
  4. Go to Application tab (if not visible, click >> to see more tabs)
  5. In the left sidebar, expand "Local Storage"
  6. Click on "https://chat.deepseek.com"
  7. Find the key named userToken
  8. Copy "value" - this is your authentication token

Method 2: From Network Tab

Alternatively, you can get the token from network requests:

  1. Visit chat.deepseek.com
  2. Log in to your account
  3. Open browser developer tools (F12)
  4. Go to Network tab
  5. Make any request in the chat
  6. Find the request headers
  7. Copy the authorization token (without 'Bearer ' prefix)

Handling Cloudflare Challenges

If you encounter Cloudflare challenges ("Just a moment..." page), you'll need to get a cf_clearance cookie. Run this command:

python -m dsk.bypass

This will:

  1. Open an undetected browser
  2. Visit DeepSeek and solve the Cloudflare challenge
  3. Capture and save the cf_clearance cookie
  4. The cookie will be automatically used in future requests

You only need to run this when:

  • You get Cloudflare challenges in your requests
  • Your existing cf_clearance cookie expires
  • You see the error "Please wait a few minutes before trying again"

The captured cookie will be stored in dsk/cookies.json and automatically used by the API.

📚 Usage

Basic Example

from ron.api import DeepSeekAPI

# Initialize with your auth token
api = DeepSeekAPI("YOUR_AUTH_TOKEN")

# Create a new chat session
chat_id = api.create_chat_session()

# Simple chat completion
prompt = "What is Python?"

response = api.chat_completion(
    chat_session_id=session_id,
    prompt
)

print(response)

📌 With Optional Parameters

🧠 Enable Thinking

response = api.chat_completion(
    chat_session_id=session_id,
    prompt="Explain black holes deeply",
    thinking_enabled=True
)

🔍 Enable Search

response = api.chat_completion(
    chat_session_id=session_id,
    prompt="Latest AI news",
    search_enabled=True
)

🧠 + 🔍 Both Together

response = api.chat_completion(
    chat_session_id=session_id,
    prompt="Explain quantum computing with research",
    thinking_enabled=True,
    search_enabled=True
)

##🔁 Multi-Turn Conversation (Same Chat)

r1 = api.chat_completion(session_id, "What is Python?")
r2 = api.chat_completion(session_id, "Explain decorators")
r3 = api.chat_completion(session_id, "Give simple examples")

print(r3)

About

Deepseek private unofficial api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages