DeepSeek V4 with OpenAI Codex Migration

A practical guide for migrating from OpenAI Codex/OpenAI API to DeepSeek V4 using OpenAI-compatible endpoints.

v1 Compatible
OpenAI API format
Code Focused
Optimized for coding
Cost Effective
Competitive pricing

Migration note: OpenAI Codex has been deprecated. This guide helps transition existing code to DeepSeek V4's OpenAI-compatible endpoint. Always test thoroughly before production use.

Why migrate from OpenAI Codex

Code-focused AI with OpenAI compatibility

OpenAI Codex was deprecated and integrated into GPT models. DeepSeek V4 offers a code-optimized alternative with an OpenAI-compatible API endpoint, making migration straightforward for most existing integrations.

FeatureOpenAI CodexDeepSeek V4
Code GenerationDeprecatedActive, optimized
API FormatOpenAI APIOpenAI-compatible
Model AccessLimited availabilityPublic API access
PricingPremium tiersCompetitive rates

Requirements

Existing Code

Codebase that previously used OpenAI Codex or OpenAI API

Required

API Provider

A DeepSeek Platform API key for OpenAI-compatible endpoint

Required

Runtime

Node.js 18+ or Python 3.8+ environment for API calls

Node.js 18+ / Python 3.8+

Migration Steps

1

Get DeepSeek OpenAI-compatible credentials

Obtain API key for OpenAI-compatible endpoint

  • Create a DeepSeek Platform account
  • Generate an API key from the dashboard
  • Note the OpenAI-compatible base URL: https://api.deepseek.com/v1
  • Store credentials securely (environment variables)
2

Update API configuration

Modify your OpenAI/Codex API calls to use DeepSeek endpoint

  • Replace base URL with https://api.deepseek.com/v1
  • Update API key to DeepSeek Platform key
  • Map model names to DeepSeek equivalents
  • Test with a simple completion request
3

Verify functionality

Run smoke tests to ensure core features work

  • Test code generation/editing workflows
  • Verify streaming responses work correctly
  • Check function/tool calling if used
  • Review error handling and rate limits

Configuration Reference

# OpenAI-compatible configuration
base_url: "https://api.deepseek.com/v1"
api_key: "<your-deepseek-api-key>"

# Model mapping
default_model: "deepseek-v4-pro[1m]"
fast_model: "deepseek-v4-flash"

# Example cURL
curl https://api.deepseek.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DEEPSEEK_API_KEY" \
  -d '{
    "model": "deepseek-v4-pro[1m]",
    "messages": [{"role": "user", "content": "Write a Python function"}]
  }'

Replace OpenAI credentials with DeepSeek equivalents. Keep API keys secure.

API Migration Comparison

Use CaseOpenAI FormatDeepSeek Notes
Code GenerationPOST /v1/completions or /v1/chat/completionsChange model to deepseek-v4-pro[1m] for best quality
Code EditingChat completions with edit instructionsFlash model for faster edits, Pro for complex refactors
Function Callingtools/functions in chat completionsVerify function schema compatibility

Troubleshooting

Authentication Failed

Verify API key is valid DeepSeek key, not OpenAI key. Check base URL is https://api.deepseek.com/v1

Model Not Found

Use documented DeepSeek model IDs: deepseek-v4-pro[1m] or deepseek-v4-flash. Do not use OpenAI model names like gpt-4

Different Response Format

DeepSeek's OpenAI compatibility is high but not 100%. Review compatibility table for edge cases

Rate Limit Errors

DeepSeek has different rate limits. Check account dashboard and implement exponential backoff

Compatibility status

What's supported by the OpenAI-compatible endpoint

DeepSeek's OpenAI-compatible endpoint covers the most commonly used APIs. Review the compatibility status before migration.

Chat completions API

Fully compatible with OpenAI format

Completions API

Legacy completions endpoint supported

Function/tool calling

Standard tool calling format supported

Streaming responses

Server-sent events work as expected

Embeddings API

Use separate embeddings endpoint if needed

Image generation

Not supported via OpenAI compatibility

Audio/speech

Not supported via OpenAI compatibility

Secure your API integration

When migrating from OpenAI to DeepSeek, review your security practices. API keys should never be committed to version control, and rate limiting should be implemented to control costs.

  • Store API keys in environment variables or secret managers
  • Implement request rate limiting and cost monitoring
  • Use separate keys for development and production
  • Rotate keys periodically and after suspected exposure
  • Audit code for hardcoded credentials before deployment

Optimize for cost and quality

DeepSeek V4 offers Pro and Flash models for different use cases. Use Pro for complex reasoning and high-quality output, Flash for faster responses on simpler tasks.

Monitor your usage through the DeepSeek dashboard and implement caching where appropriate to reduce redundant API calls.

Open the DeepSeek API pricing guide

Common Workflows

Code Generation

Generate code from natural language descriptions

  • Send prompt to chat completions
  • Specify desired language/framework
  • Review and test generated code

Code Refactoring

Improve existing code structure and quality

  • Provide code context
  • Describe refactoring goals
  • Apply suggested changes

Debugging Assistance

Get help identifying and fixing bugs

  • Share error messages and code
  • Describe expected behavior
  • Implement suggested fixes

Frequently Asked Questions

Is OpenAI Codex still available?

OpenAI Codex has been deprecated and integrated into GPT models. This guide helps migrate to DeepSeek V4 as an alternative for code-focused AI tasks.

What's the difference between OpenAI and DeepSeek endpoints?

DeepSeek provides an OpenAI-compatible endpoint at https://api.deepseek.com/v1. The request/response format is largely the same, but model IDs and some capabilities differ.

Can I use the same code with minimal changes?

Yes, for most use cases. Update the base URL, API key, and model IDs. Some advanced features may need adjustment per the compatibility table.

Which DeepSeek model should I use?

Use deepseek-v4-pro[1m] for complex reasoning and high-quality output. Use deepseek-v4-flash for faster responses and simpler tasks.

Are function calling and tools supported?

Yes, DeepSeek's OpenAI-compatible endpoint supports function/tool calling. Verify your function schemas work with the compatibility layer.

What about image and multimodal capabilities?

DeepSeek's OpenAI compatibility focuses on text/code. Check the current compatibility table for multimodal support status.