Last updated
How to Integrate the DeepSeek API
You can integrate the DeepSeek API by using standard OpenAI-compatible SDKs to send requests to a proxy endpoint. This approach lets you run your existing client code against an uncensored model without modifying your authentication logic or switching libraries.
Summary
- Use the standard OpenAI SDK with a custom base URL to route requests to the proxy.
- Set the model ID to "uncensored" to disable content refusals for lawful adult topics.
- Streaming responses deliver tokens via Server-Sent Events for low-latency user interfaces.
- Tool calling and JSON mode are supported by configuring the request body parameters.
Prerequisites: Environment Setup
Start by ensuring your development environment has the necessary SDK installed. You need a language runtime like Python or Node.js and a way to store your API credentials securely. This setup is identical to using any other OpenAI-compatible service.
You do not need to install vendor-specific drivers. The proxy handles all model inference, so your machine only needs to send HTTP requests and parse JSON responses. This reduces dependency overhead and keeps your project light.
Installing the Official SDK
Install the official SDK for your preferred language to handle authentication and request serialization. For Python, use pip install openai. For Node.js, run npm install openai. This library manages the underlying HTTP connections.
The SDK abstracts away the complexity of building JSON payloads. You can focus on defining your prompt and handling the returned tokens. This standardization means you can switch providers later by changing just the base URL.
from openai import OpenAI
client = OpenAI(base_url="https://api.deepseekpago.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)
Configuring Base URL and Key
Point your SDK client to the proxy base URL and inject your API key. This configuration step directs traffic away from the standard OpenAI servers. You must set the base_url to https://api.deepseekpago.com/v1.
Pass your key via the api_key parameter. This key is generated when you sign up on the site. It authenticates your requests and tracks your prepaid credit usage. Without this configuration, your requests will fail with a 404 or 401 error.
Making Your First Request
Send a simple text completion to verify connectivity and model behavior. Use the model ID uncensored to access the specific model running on the proxy. This model is tuned to answer without content refusals for lawful adult use.
The request body includes the messages array and the model identifier. The response contains the generated text in the content field. This confirms that your integration is working correctly with the uncensored model.
curl https://api.deepseekpago.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Generate a list of top five open source llms"}]
}'
Enabling Streaming Responses
Enable streaming by setting stream: true in your request. This returns Server-Sent Events (SSE) instead of a single JSON object. You receive tokens as they are generated, which improves perceived latency for end-users.
Handle the stream by iterating through the chunks. The final chunk contains the total token usage. This allows you to monitor costs in real-time without waiting for the full response to complete.
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Using Tools and Function Calling
Define tools in the request body to let the model generate structured outputs. Pass a list of function definitions in the tools parameter. The model will return a function call instead of plain text when appropriate.
This feature works exactly like the OpenAI function calling API. You can integrate this into your application logic to execute code or update databases. The proxy supports this standard protocol without modification.
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.deepseekpago.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);
Enforcing JSON Output Format
Force the model to return valid JSON by setting response_format to {"type": "json_object"}. This is useful for parsing data into your application. It reduces the need for post-processing regex patterns.
The model adheres to this constraint strictly. If the output is not valid JSON, the request may fail. This ensures your pipeline remains robust when integrating with automated systems. You can also set temperature and top_p to control creativity.
Handling Errors and Rate Limits
The API enforces a limit of 300 requests per minute per key. If you exceed this, you receive a 429 error. You can also have up to 8 concurrent requests per key. Respect these limits to avoid service interruptions.
Errors are returned as standard JSON objects with an error code and message. Handle these gracefully in your code. Retry logic with exponential backoff is recommended for transient errors like 429 or 503 responses.
Monitoring Token Usage
Track your prepaid credit usage by monitoring token counts. The final chunk in a streaming response includes the usage object. This shows input and output token counts.
Prices are $0.15 per 1M input tokens and $0.50 per 1M output tokens. Errors are free. You can calculate costs locally by multiplying token counts by these rates. This helps you budget your crypto top-ups accurately.
Frequently asked questions
How do I get an API key for deepseek pago?
Sign up using Google or email on the 'Get API key' page. The key is shown immediately. You need a prepaid credit account to start using it.
Is the uncensored model the same as DeepSeek?
No. The model ID is "uncensored" and runs on our own servers. It is an open-weight model tuned for fewer refusals, but it is not DeepSeek, GPT, or any other vendor's model.
What payment methods are accepted?
We accept only crypto: USDT (TRC20) or USDC (Base). Top-ups range from $20 to $500.
Does the credit expire?
No. Your prepaid credit never expires. You can use it whenever you need it. Trial credit is valid for 7 days.
Retrieve your API key
Register, copy the key, update the endpoint. Done.