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

Introduction

Integrating artificial intelligence into applications is no longer the prerogative of giants — today, any developer can connect a powerful language model via API. The three market leaders — OpenAI, Anthropic, and DeepSeek — offer different approaches to authentication, streaming, and system prompt management. In this guide, we'll break down the practical nuances of working with each API, compare pricing, and provide code templates for a quick start.

Authentication and Basic Requests

OpenAI API

OpenAI uses a Bearer token in the Authorization header. You can obtain a key in your personal account on platform.openai.com. Example in Python:

import openai

openai.api_key = "sk-..."
response = openai.ChatCompletion.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Anthropic API

Anthropic (Claude) requires specifying x-api-key in headers and the API version. Important: Anthropic uses the anthropic-version format in requests. Example:

import requests

headers = {
    "x-api-key": "sk-ant-...",
    "anthropic-version": "2023-06-01"
}
data = {
    "model": "claude-3-opus-20240229",
    "messages": [{"role": "user", "content": "Hi"}]
}
response = requests.post("https://api.anthropic.com/v1/messages", json=data, headers=headers)
print(response.json()["content"][0]["text"])

DeepSeek API

DeepSeek offers simpler authentication — via Authorization: Bearer <token>. Endpoint: https://api.deepseek.com/v1/chat/completions. DeepSeek supports the DeepSeek-V2 model, known for its low cost and high inference speed.

Real-Time Response Streaming

OpenAI

OpenAI supports stream=True:

stream = openai.ChatCompletion.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a short poem"}],
    stream=True
)
for chunk in stream:
    if chunk.choices[0].delta.get("content"):
        print(chunk.choices[0].delta.content, end="")

Anthropic

Anthropic implements streaming via Server-Sent Events (SSE):

import requests

headers = {
    "x-api-key": "sk-ant-...",
    "anthropic-version": "2023-06-01"
}
data = {
    "model": "claude-3-haiku-20240307",
    "messages": [{"role": "user", "content": "Tell me about yourself"}],
    "stream": True
}
with requests.post("https://api.anthropic.com/v1/messages", json=data, headers=headers, stream=True) as r:
    for line in r.iter_lines():
        if line:
            print(line.decode())

DeepSeek

DeepSeek also supports streaming via SSE, similar to OpenAI:

import requests

headers = {"Authorization": "Bearer <token>"}
data = {
    "model": "deepseek-chat",
    "messages": [{"role": "user", "content": "Come up with a startup idea"}],
    "stream": True
}
with requests.post("https://api.deepseek.com/v1/chat/completions", json=data, headers=headers, stream=True) as r:
    for line in r.iter_lines():
        if line:
            print(line.decode())

System Prompts: Configuring Model Behavior

A system prompt is an instruction that sets the style and constraints of the response. All three providers handle it differently:

Provider Field for System Prompt Example
OpenAI messages[0] with role "system" {"role": "system", "content": "You are an experienced copywriter"}
Anthropic system (outside the messages array) "system": "You are a programming assistant"
DeepSeek messages[0] with role "system" {"role": "system", "content": "Answer briefly"}

Practical Tip

Use system prompts to control tone, response length, and avoid sensitive topics. For example, for a tech support chatbot: "Answer politely, do not give medical advice, answer only in Russian."

Pricing and Limits

Cost comparison (data as of June 2026):

| Model | Input (per 1M tokens) | Output (per 1M tokens) | Speed

← All posts

Comments