OpenAI, Anthropic, DeepSeek API: A Complete Guide to Integrating AI Models in 2026

Introduction

Integrating language models into business processes is no longer an experiment—it's the standard. However, choosing a provider and configuring the API still raises questions. OpenAI, Anthropic, and DeepSeek offer different approaches to authentication, streaming, and pricing. In this guide, we'll break down the practical nuances of working with each API so you can quickly launch an AI solution without unnecessary costs.

Authentication and Basic Requests

All three providers use API keys, but the methods of passing them differ.

OpenAI API

import openai
openai.api_key = "sk-your-key"
response = openai.ChatCompletion.create(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Hello"}]
)

The key is passed via the Authorization: Bearer header. Both standard requests and streaming are supported.

Anthropic API

import anthropic
client = anthropic.Anthropic(api_key="sk-ant-your-key")
message = client.messages.create(
    model="claude-4-opus",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}]
)

Anthropic requires mandatory specification of max_tokens and uses a different format for the system prompt—via the system parameter, not in the messages array.

DeepSeek API

import requests
headers = {"Authorization": "Bearer ds-your-key"}
data = {
    "model": "deepseek-chat",
    "messages": [{"role": "user", "content": "Hello"}]
}
response = requests.post("https://api.deepseek.com/v1/chat/completions", headers=headers, json=data)

DeepSeek is fully compatible with the OpenAI format, simplifying migration. The only difference is the base URL api.deepseek.com.

Streaming Responses

Streaming is critical for user experience: no one wants to wait 10 seconds for a full response.

Provider Streaming Parameter Data Format Feature
OpenAI stream=True Server-Sent Events Supports tokens and logits
Anthropic stream=True Server-Sent Events Requires separate handling of content_block_delta
DeepSeek stream=True Server-Sent Events Full compatibility with OpenAI SSE

Example for DeepSeek:

for chunk in response.iter_lines():
    if chunk:
        print(chunk.decode('utf-8'))

Important: In Anthropic, streaming events have a complex structure—first comes message_start, then a series of content_block_delta, and ends with message_stop. OpenAI and DeepSeek send data more simply: each chunk contains a token delta.

System Prompts and Context

System prompts are the foundation for controlling model behavior. Let's examine the nuances of each API.

OpenAI

The system prompt is passed as a separate message with the system role:

messages=[
    {"role": "system", "content": "You are an SEO expert. Answer concisely and to the point."},
    {"role": "user", "content": "How to improve meta description?"}
]

Anthropic

Here, the system prompt is a separate parameter:

client.messages.create(
    model="claude-4-opus",
    system="You are an SEO expert. Answer concisely and to the point.",
    messages=[{"role": "user", "content": "How to improve meta description?"}]
)

DeepSeek

Full compatibility with OpenAI:

messages=[
    {"role": "system", "content": "You are an SEO expert."},
    {"role": "user", "content": "How to improve meta description?"}
]

Tip: For complex tasks, use system prompts of 500-1000 characters. This is especially important when creating AI agents—read more in the article AI Agents for Business.

Pricing: What to Choose in 2026

API cost is a key factor when scaling. Let's compare current rates (prices per 1M tokens):

Model Input Output Context
OpenAI GPT-4.1 $15 $60 128K
Anthropic Claude-4 Opus $25 $100 200K
DeepSeek Chat $0.5 $2 128K

Analysis:
- DeepSeek — price leader, ideal for prototypes and

← All posts

Comments