DeepSeek API Integration Guide: OpenAI-Compatible Requests through ECAIX
DeepSeek API Integration Guide: OpenAI-Compatible Requests through ECAIX
This guide shows how to test a DeepSeek model ID through ECAIX using an OpenAI-compatible API endpoint. It covers the smallest working request, Python and curl examples, model-ID verification, streaming, structured output, tools, and a diagnostic path for common errors.
The guide describes ECAIX gateway access to a model ID exposed in the current ECAIX catalog. It does not claim that ECAIX is the official DeepSeek API endpoint or that every DeepSeek feature is available through every gateway route. Check the live model page and the provider documentation before moving a workload to production.
What this guide verifies
The examples use the ECAIX OpenAI-compatible path and a model ID currently visible in the public catalog at publication time. Availability, routing, limits, pricing, and supported features can change. Treat the catalog and API documentation as the current source of truth.
Quick start
Use this sequence if you already have an OpenAI SDK application:
- Open the DeepSeek v4.1 Flash model page and confirm that the ID is available.
- Create an ECAIX API key.
- Set the OpenAI-compatible base URL to
https://ecaix.com/api/ai/v1. - Keep the SDK and application code unchanged where possible.
- Run the minimal request below.
- Add streaming, JSON output, or tools only after the basic request works.
Endpoint and model ID
For OpenAI-compatible clients, use:
Base URL: https://ecaix.com/api/ai/v1
Model: deepseek-v4.1-flash
The model ID is not a permanent promise in a blog post. Confirm it in the live model directory before every new integration or deployment. If you need a different DeepSeek family member, copy the exact ID from the model detail page instead of guessing a suffix.
The endpoint format also matters. The SDK should receive the base path ending at /v1; the client adds /chat/completions or another operation path. Do not append /chat/completions to base_url when the SDK already appends it.
Python with the OpenAI SDK
Install or upgrade the OpenAI Python SDK in your virtual environment:
python -m pip install --upgrade openai
Then use the ECAIX base URL and API key:
const client = new OpenAI({
apiKey: process.env.ECAIX_API_KEY,
baseURL: "https://ecaix.com/api/ai/v1",
});
const response = await client.chat.completions.create({
model: "deepseek-v4.1-flash",
messages: [
{ role: "user", content: "Return one short sentence about API testing." },
],
max_tokens: 128,
});
console.log(response.choices[0].message.content);
Use server-side code for the API request. A browser application should call your own backend rather than exposing an ECAIX key in client-side JavaScript.
Curl diagnostic request
When an SDK fails, remove the SDK from the equation and test the endpoint directly. Save headers and the body separately so that you can distinguish an HTTP problem from a response-format problem.
curl -sS -D /tmp/ecaix-deepseek-headers.txt \
-o /tmp/ecaix-deepseek-response.json \
-w '\nHTTP %{http_code}\n' \
"https://ecaix.com/api/ai/v1/chat/completions" \
-H "Authorization: Bearer ${ECAIX_API_KEY}" \
-H "content-type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"messages": [
{"role": "user", "content": "Reply with one short sentence."}
],
"max_tokens": 128
}'
Do not paste the saved headers or response into a public ticket without removing API keys, request IDs, prompts, repository paths, and customer data.
How to diagnose the response
Use the following order:
- HTTP status: determine whether the request reached a valid endpoint.
- Response body: read the provider or gateway error code.
- Model ID: copy the exact ID from the current model directory.
- Authentication: check the key header, account, and permissions.
- Request shape: reduce the body to
model,messages, and a small output limit. - Feature fields: add streaming, JSON, or tools one at a time.
- SDK behavior: compare the SDK request with the direct curl request.
This prevents a client library issue from being confused with model routing or account permissions.
Streaming responses
If the application needs incremental output, add streaming only after a normal request succeeds:
stream = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Summarize API retries in three points."}],
stream=True,
max_tokens=256,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
The exact event behavior depends on the endpoint and SDK. Verify how your framework handles an empty delta, a final usage event, connection interruption, and [DONE]-style termination. Do not call a streaming implementation production-ready until you have tested disconnects and retries.
Structured output and JSON
If you need machine-readable output, start with an ordinary request and then add the smallest structured-output option supported by the endpoint and model. Validate the returned content with a real JSON parser. A prompt that says “return JSON” is not the same as a schema-enforced response.
import json
response = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[
{
"role": "user",
"content": "Return a JSON object with keys title and priority."
}
],
response_format={"type": "json_object"},
max_tokens=128,
)
payload = json.loads(response.choices[0].message.content)
print(payload["title"])
Whether response_format is accepted can depend on the model and route. If the endpoint returns an unsupported-parameter error, remove the field and verify the route documentation before trying another format.
Function calling and tools
Tool calling needs a separate test from text generation. Start with one harmless function and inspect the returned name and arguments before executing anything.
tools = [
{
"type": "function",
"function": {
"name": "get_demo_status",
"description": "Return a fixed status for a local compatibility test.",
"parameters": {
"type": "object",
"properties": {},
"additionalProperties": False,
},
},
}
]
response = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Check the demo status."}],
tools=tools,
tool_choice="auto",
max_tokens=128,
)
print(response.choices[0].message.tool_calls)
A model may return a valid text response while tool calling fails because of schema conversion, unsupported parameters, or client-specific behavior. Never execute returned tool arguments against a production system before validating the schema and adding authorization checks.
OpenAI-compatible and Anthropic-compatible paths
ECAIX exposes different compatibility surfaces for different clients:
| Client or workflow | Documentation path | What to verify |
|---|---|---|
| OpenAI Python/Node SDK | /api/ai/v1 | Chat Completions, Responses, streaming, tools |
| Anthropic-style client | /api/ai/v1/anthropic | Messages fields, headers, content blocks |
| Claude Code third-party workflow | /api/ai/v1/anthropic | Provider-specific behavior; not Anthropic official support |
Read the Chat Completions documentation, Responses documentation, and Anthropic Messages documentation before choosing a path. The same model ID may not expose identical fields or behavior on every compatibility surface.
Current model details
Use the live detail pages for capability and availability checks:
These pages are more reliable than a static article for current model IDs, context information, and pricing links.
Common errors
| Status or symptom | Likely cause | Diagnostic action |
|---|---|---|
401 | Missing or invalid bearer token | Check Authorization, environment variable, and key status |
403 | Key or account lacks permission | Check account access and model availability |
404 | Wrong base URL or route suffix | Use /api/ai/v1/chat/completions for the direct curl test |
400 | Invalid body or unsupported field | Remove optional fields and retry the minimal body |
429 | Rate or quota limit | Record response headers, slow down, and check account limits |
5xx | Gateway or upstream failure | Save request time and response ID; retry according to your policy |
| Model not found | Typo, removed model, or routing mismatch | Copy the exact model ID from /models |
| Text works, tools fail | Tool schema or model capability mismatch | Test one harmless function and inspect returned arguments |
| SDK works differently from curl | SDK defaults or path construction | Print the SDK request configuration and compare paths |
Security and production checklist
Before moving beyond a test project, confirm:
- API keys are stored server-side and can be rotated.
- Prompts and responses do not contain unapproved secrets or customer data.
- You understand whether the gateway logs requests and how long logs are retained.
- Model availability and pricing are checked from the live pages.
- Timeouts, retries, idempotency, and rate limits are handled by your application.
- Streaming disconnects do not create duplicate jobs.
- Tool calls have allowlists, validation, authorization, and audit logs.
- Provider and gateway terms permit the workload you plan to send.
Record the integration before release
Write down the date, client version, model ID, endpoint, HTTP status, and the feature tests you actually ran. If a test was not performed, mark it as unverified. This record makes the next model or gateway update easier to compare and prevents an old blog example from becoming an unsupported production assumption.
FAQ
Is this the official DeepSeek API endpoint?
No. This article documents ECAIX gateway access to a model ID exposed in the ECAIX catalog. Use the official DeepSeek API documentation for DeepSeek's native endpoint, account rules, and provider-specific capabilities.
Can I use the OpenAI SDK without rewriting my application?
Many OpenAI SDK applications can start by changing the base URL, API key, and model ID. You still need to test field support, streaming, tool calls, response formats, error handling, and any provider-specific features used by your application.
Which DeepSeek model should I use?
Start with the model directory and choose by task: coding, reasoning, context length, multimodal input, or cost requirements. Do not choose only by a name copied from an old article. Verify the current model ID and test it against your own prompts.
Can I use this with Claude Code?
The Anthropic-compatible path can be tested as a third-party provider workflow, but Anthropic does not support routing Claude Code to non-Claude models through a gateway. Do not present this as official Anthropic support or as a guarantee of full Claude Code compatibility.
Where do I check current pricing and limits?
Use the ECAIX pricing page, model directory, and your account controls. Do not hard-code a price from this article into an application.
Next steps
- Confirm the model ID in the current DeepSeek model page.
- Create an ECAIX API key.
- Read the Chat Completions docs.
- Run the direct curl diagnostic.
- Move to the SDK example only after the direct request succeeds.
- Add streaming, JSON, or tools one feature at a time.