---
name: clade-migration-deep-dive
description: "Migrate from OpenAI/GPT to Anthropic/Claude — API differences,

  Use when working with migration-deep-dive patterns.

  prompt adaptation, SDK swap, and feature mapping.

  Trigger with \"migrate to claude\", \"openai to anthropic\",

  \"switch from gpt to claude\", \"replace openai with anthropic\"."
allowed-tools: Read, Write, Edit, Grep
version: 1.1.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - anthropic
  - claude
  - migration
  - openai
compatibility: Designed for Claude Code
title: clade-migration-deep-dive
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/clade-migration-deep-dive
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/one-pager.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clade-migration-deep-dive/references/one-pager.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/clade-migration-deep-dive`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/clade-migration-deep-dive`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/clade-migration-deep-dive) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/clade-migration-deep-dive`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/clade-migration-deep-dive --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/clade-migration-deep-dive --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Migrate from OpenAI to Anthropic

## Overview

Migrate from OpenAI/GPT to Anthropic/Claude. Covers the complete API mapping (endpoints, models, response shapes), SDK swap with before/after code, five key differences (max_tokens required, system as top-level param, alternating messages, response path, streaming events), and tool use migration.

## API Mapping

| OpenAI | Anthropic | Notes |
|--------|-----------|-------|
| `openai.chat.completions.create()` | `anthropic.messages.create()` | Different request/response shape |
| `model: 'gpt-4o'` | `model: 'claude-sonnet-4-20250514'` | Different model IDs |
| `response.choices[0].message.content` | `response.content[0].text` | Different response path |
| `system` in messages array | `system` as separate parameter | Claude uses top-level `system` |
| `response_format: { type: 'json_object' }` | System prompt: "Respond in JSON only" | No native JSON mode |
| `tools` / `function_calling` | `tools` (similar but different schema) | Input schema differences |
| `openai.embeddings.create()` | N/A — use Voyage or Cohere | No embeddings API |

## SDK Swap

## Instructions

### Step 1: Before (OpenAI)

```typescript
import OpenAI from 'openai';
const openai = new OpenAI();

const response = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [
    { role: 'system', content: 'You are helpful.' },
    { role: 'user', content: 'Hello' },
  ],
});
console.log(response.choices[0].message.content);
```

### Step 2: After (Anthropic)

```typescript
import Anthropic from '@claude-ai/sdk';
const anthropic = new Anthropic();

const response = await anthropic.messages.create({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024, // Required (not optional like OpenAI)
  system: 'You are helpful.', // Separate from messages
  messages: [
    { role: 'user', content: 'Hello' },
  ],
});
console.log(response.content[0].text);
```

## Key Differences

1. **`max_tokens` is required** — OpenAI defaults it, Anthropic requires it
2. **`system` is a top-level param** — not a message in the array
3. **First message must be `user`** — can't start with assistant
4. **Messages must alternate** — no two user or two assistant messages in a row
5. **Response shape** — `content[0].text` not `choices[0].message.content`
6. **Streaming events** — different event types and structure

## Tool Use Migration

```typescript
// OpenAI tool definition
{ type: 'function', function: { name: 'get_weather', parameters: { ... } } }

// Anthropic tool definition
{ name: 'get_weather', input_schema: { ... } }  // Flatter structure
```

## Grep & Replace

```bash
# Find all OpenAI imports
grep -rn "from 'openai'" --include="*.ts" .
grep -rn "import OpenAI" --include="*.ts" .

# Find response access patterns to update
grep -rn "choices\[0\]" --include="*.ts" .
grep -rn "message.content" --include="*.ts" .  # May need updating
```

## Output

- All `openai` imports replaced with `@claude-ai/sdk`
- Response access patterns updated (`choices[0].message.content` → `content[0].text`)
- System prompts moved from messages array to top-level `system` parameter
- `max_tokens` added to all API calls (required, not optional)
- Tool definitions restructured to Anthropic format

## Error Handling

| Error | Cause | Solution |
|-------|-------|----------|
| API Error | Check error type and status code | See `clade-common-errors` |

## Examples

See API Mapping table, Before/After SDK code, Key Differences list, Tool Use Migration, and Grep & Replace commands above.

## Resources

- [Anthropic Messages API](https://platform.claude.com/docs/en/api/messages)
- [Migration Guide](https://platform.claude.com/docs/en/models/overview)

## Next Steps

See `clade-sdk-patterns` for production Anthropic SDK patterns.

## Prerequisites

- Existing OpenAI integration to migrate
- Access to codebase with search capability
- Test suite for comparing outputs between providers
