Bastio
Providers

DeepSeek Integration

Complete guide to using DeepSeek with Bastio for DeepSeek-V3 chat and reasoning models.

DeepSeek

Access DeepSeek's powerful AI models with advanced reasoning capabilities through Bastio's security layer.

Overview

DeepSeek offers state-of-the-art AI models with exceptional performance and competitive pricing. With Bastio, you can:

  • Advanced reasoning - Access DeepSeek Reasoner with thinking mode for complex problem-solving
  • Cost-effective - Industry-leading pricing at $0.28/1M input tokens
  • OpenAI-compatible - Drop-in replacement API, no code changes needed
  • Full security coverage - All Bastio security features work seamlessly
  • Cache savings - 90% discount on cached prompts ($0.028/1M)

Why DeepSeek?

DeepSeek provides exceptional value with advanced capabilities:

FeatureDeepSeekGPT-4oClaude Sonnet
Input Price (1M tokens)$0.28$2.50$3.00
Output Price (1M tokens)$0.42$10.00$15.00
Cache Hit Price$0.028N/A$0.30
Context Window128K128K200K
Reasoning ModeYesNoNo
Tool CallingYesYesYes

Supported Models

DeepSeek Chat

General-purpose chat model using DeepSeek-V3.2:

ModelContextMax OutputInput PriceOutput PriceToolsJSON
deepseek-chat128K tokens8K tokens$0.28/1M$0.42/1MYesYes

Best for: General chat, code generation, analysis, and everyday tasks.

DeepSeek Reasoner

Advanced reasoning model with thinking mode:

ModelContextMax OutputInput PriceOutput PriceReasoningTools
deepseek-reasoner128K tokens64K tokens$0.28/1M$0.42/1MYesYes

Best for: Complex problem-solving, math, logic, multi-step reasoning.

Quick Start

Prerequisites

  1. DeepSeek API key from platform.deepseek.com
  2. Bastio account

Step 1: Get Your DeepSeek API Key

  1. Go to platform.deepseek.com
  2. Sign in or create an account
  3. Navigate to API Keys
  4. Click Create new secret key
  5. Copy your API key

Step 2: Create a Proxy in Bastio

  1. Go to Dashboard > Proxies > Create New Proxy
  2. Select DeepSeek as provider
  3. Choose Your API Keys (BYOK) mode
  4. Enter your DeepSeek API key
  5. Click Create Proxy

Step 3: Start Making Requests

from openai import OpenAI

client = OpenAI(
    base_url="https://api.bastio.com/v1/guard/{PROXY_ID}/v1",
    api_key="your-bastio-api-key"
)

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "user", "content": "Explain quantum computing"}
    ]
)

print(response.choices[0].message.content)

BYOK Mode (Bring Your Own Key)

DeepSeek integration is BYOK-only. Use your own DeepSeek API key with Bastio's security layer.

Via Dashboard

  1. Go to Dashboard > Proxies > Create New Proxy
  2. Select DeepSeek as provider
  3. Choose Your API Keys (BYOK) mode
  4. Enter your DeepSeek API key
  5. Select a default model (optional)
  6. Click Create Proxy

Via API

# Create DeepSeek proxy
curl -X POST https://api.bastio.com/proxy \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production DeepSeek",
    "provider": "deepseek",
    "llm_mode": "byok",
    "model_behavior": "passthrough"
  }'

# Add DeepSeek API key
curl -X POST https://api.bastio.com/keys/provider \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "deepseek",
    "key_name": "DeepSeek Production",
    "api_key": "sk-your-deepseek-key"
  }'

Code Examples

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(
    base_url="https://api.bastio.com/v1/guard/{PROXY_ID}/v1",
    api_key="your-bastio-api-key"
)

# Using DeepSeek Chat
response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Write a Python function to sort a list"}
    ],
    temperature=0.7
)

print(response.choices[0].message.content)

JavaScript/TypeScript

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.bastio.com/v1/guard/{PROXY_ID}/v1',
  apiKey: process.env.BASTIO_API_KEY,
});

// Using DeepSeek Reasoner for complex problems
const response = await client.chat.completions.create({
  model: 'deepseek-reasoner',
  messages: [
    { role: 'user', content: 'Solve this step by step: If 3x + 5 = 17, find x' }
  ],
});

console.log(response.choices[0].message.content);

Streaming

from openai import OpenAI

client = OpenAI(
    base_url="https://api.bastio.com/v1/guard/{PROXY_ID}/v1",
    api_key="your-bastio-api-key"
)

stream = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "user", "content": "Write a short story about AI"}
    ],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Tool/Function Calling

from openai import OpenAI
import json

client = OpenAI(
    base_url="https://api.bastio.com/v1/guard/{PROXY_ID}/v1",
    api_key="your-bastio-api-key"
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather in a location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "City name"
                    }
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "user", "content": "What's the weather in San Francisco?"}
    ],
    tools=tools,
    tool_choice="auto"
)

# Handle tool calls
if response.choices[0].message.tool_calls:
    for tool_call in response.choices[0].message.tool_calls:
        print(f"Function: {tool_call.function.name}")
        print(f"Arguments: {tool_call.function.arguments}")

JSON Mode

from openai import OpenAI

client = OpenAI(
    base_url="https://api.bastio.com/v1/guard/{PROXY_ID}/v1",
    api_key="your-bastio-api-key"
)

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "system", "content": "Respond in JSON format only."},
        {"role": "user", "content": "List 3 programming languages with their use cases"}
    ],
    response_format={"type": "json_object"}
)

import json
data = json.loads(response.choices[0].message.content)
print(data)

Using DeepSeek Reasoner

DeepSeek Reasoner includes a "thinking mode" for complex reasoning tasks. The model shows its reasoning process before providing the final answer.

When to Use Reasoner

  • Math problems - Step-by-step calculations
  • Logic puzzles - Deductive reasoning
  • Code debugging - Systematic analysis
  • Complex analysis - Multi-factor decision making
  • Research - Hypothesis testing and evaluation

Reasoner Example

from openai import OpenAI

client = OpenAI(
    base_url="https://api.bastio.com/v1/guard/{PROXY_ID}/v1",
    api_key="your-bastio-api-key"
)

# Reasoner excels at complex problems
response = client.chat.completions.create(
    model="deepseek-reasoner",
    messages=[
        {"role": "user", "content": """
        A farmer has 100 acres. He wants to plant wheat and corn.
        - Wheat yields $200/acre profit, needs 3 workers/acre
        - Corn yields $300/acre profit, needs 5 workers/acre
        - He has 350 workers available
        - He must plant at least 20 acres of wheat (contract)

        How should he allocate land to maximize profit?
        """}
    ],
    max_tokens=4096
)

print(response.choices[0].message.content)

Reasoner vs Chat Comparison

Task TypeUse ChatUse Reasoner
Simple Q&AYesNo
Code generationYesFor complex algorithms
Math problemsSimpleComplex multi-step
Creative writingYesNo
AnalysisBasicIn-depth
DebuggingSimpleComplex issues

Pricing & Cost Optimization

Current Pricing

ComponentPrice
Input tokens$0.28/1M
Input tokens (cache hit)$0.028/1M
Output tokens$0.42/1M

Cache Hit Optimization

DeepSeek offers significant savings for repeated prompts:

  • Cache miss: $0.28/1M tokens
  • Cache hit: $0.028/1M tokens (90% savings!)

Tips for maximizing cache hits:

  1. Use consistent system prompts
  2. Batch similar requests
  3. Structure prompts with static prefix + dynamic suffix

Cost Comparison Example

For 1M input tokens + 500K output tokens:

ProviderCost
DeepSeek (cache miss)$0.49
DeepSeek (cache hit)$0.24
GPT-4o$7.50
Claude 3.5 Sonnet$10.50

Troubleshooting

Invalid API Key

Error: Authentication error or Invalid API key

Solutions:

  1. Verify API key is correct (starts with sk-)
  2. Check API key hasn't been revoked
  3. Ensure you have credits in your DeepSeek account
  4. Test key directly with DeepSeek API

Rate Limiting

Error: Rate limit exceeded

Solutions:

  1. Reduce request frequency
  2. Implement exponential backoff
  3. Check your tier limits on platform.deepseek.com
  4. Consider upgrading your DeepSeek account

Model Not Found

Error: Model not found

Solutions:

  1. Use correct model names: deepseek-chat or deepseek-reasoner
  2. Check for typos in model name
  3. Ensure model is available in your region

Context Length Exceeded

Error: Context length exceeded

Solutions:

  1. Both models support 128K tokens
  2. Reduce prompt/conversation length
  3. Summarize earlier messages
  4. Use max_tokens to limit response length

Streaming Issues

Error: Chunks not received or incomplete

Solutions:

  1. Ensure stream=True is set
  2. Check network connectivity
  3. Implement timeout handling
  4. Verify server supports SSE

Best Practices

1. Model Selection

  • Use deepseek-chat for general tasks
  • Use deepseek-reasoner only for complex reasoning
  • Don't use Reasoner for simple Q&A (wasteful)

2. Prompt Engineering

  • Be clear and specific
  • Use system prompts for consistent behavior
  • Structure complex prompts logically
  • Provide examples for desired output format

3. Cost Management

  • Monitor usage in Bastio dashboard
  • Set up spending alerts
  • Optimize prompts to reduce tokens
  • Leverage cache hits with consistent prefixes

4. Error Handling

  • Implement retry logic with backoff
  • Handle rate limits gracefully
  • Log errors for debugging
  • Set appropriate timeouts

API Reference

Supported Endpoints

EndpointSupported
/v1/chat/completionsYes
/v1/modelsYes
/v1/embeddingsNo

Request Parameters

ParameterSupportedNotes
modelYesdeepseek-chat or deepseek-reasoner
messagesYesStandard chat format
temperatureYes0-2
top_pYes0-1
max_tokensYesUp to 8K (chat) or 64K (reasoner)
streamYesSSE format
toolsYesFunction calling
tool_choiceYesauto, none, or specific
response_formatYes{"type": "json_object"}
frequency_penaltyYes-2 to 2
presence_penaltyYes-2 to 2
stopYesUp to 4 sequences

Frequently Asked Questions

Q: What's the difference between DeepSeek Chat and Reasoner?

A: Chat is a fast general-purpose model. Reasoner includes "thinking mode" that shows step-by-step reasoning before answering, making it better for complex problems but slower and using more tokens.

Q: Does DeepSeek support vision/images?

A: No, DeepSeek currently only supports text inputs. For vision tasks, consider using GPT-4o or Claude 3.

Q: How do I get cache hit pricing?

A: Cache hits occur automatically when you send prompts with the same prefix. DeepSeek caches the computation of common prompt prefixes. Use consistent system prompts and templates to maximize cache hits.

Q: Does streaming work with DeepSeek?

A: Yes, both models fully support streaming responses via Server-Sent Events (SSE).

Q: Can I use DeepSeek for production workloads?

A: Yes, DeepSeek offers production-ready APIs with high availability. Check platform.deepseek.com for current SLAs and rate limits.

Q: What languages does DeepSeek support?

A: DeepSeek supports many languages including English, Chinese, and other major languages. Performance may vary by language.

Additional Resources


Need help? Contact hello@bastio.com or visit our support page.