---
name: groq-migration-deep-dive
description: |-
  Use when you are moving a codebase off OpenAI, Anthropic, or another LLM
  provider onto Groq (or between Groq model generations) and want a
  zero-downtime, feature-flagged cutover with a benchmark and rollback plan.
  Trigger with phrases like "migrate to groq", "switch to groq",
  "groq migration", "openai to groq", "groq replatform".
allowed-tools: Read, Write, Edit, Bash(npm:*), Bash(node:*), Bash(kubectl:*)
version: 1.11.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - groq
  - migration
compatibility: Designed for Claude Code
title: groq-migration-deep-dive
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/groq-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/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-migration-deep-dive/references/examples.md), [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-migration-deep-dive/references/implementation.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/groq-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/groq-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/groq-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/groq-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/groq-migration-deep-dive --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/groq-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.

# Groq Migration Deep Dive

## Current State

!`npm list groq-sdk openai @anthropic-ai/sdk 2>/dev/null | grep -E "groq|openai|anthropic" || echo 'No LLM SDKs found'`

## Overview

Migrate to Groq from OpenAI, Anthropic, or other LLM providers. Groq's
OpenAI-compatible API makes migration straightforward — the primary changes
are a different SDK import, different model IDs, and different response
metadata. The reward is 10-50x faster inference.

The safe path is a provider-abstraction layer plus feature-flagged traffic
shifting: route a small canary to Groq, benchmark quality and speed, ramp to
100%, and keep a one-flag rollback the whole way.

## Migration Complexity

| Source | Complexity | Key Changes |
|--------|-----------|-------------|
| OpenAI | Low | Import, model IDs, base URL — API shape is identical |
| Anthropic | Medium | Different API shape, message format, streaming protocol |
| Local LLMs | Medium | Remove infra, add API calls |
| Other cloud (Bedrock, Vertex) | Medium | Remove cloud SDK, add groq-sdk |

## Prerequisites

- A Groq API key (`GROQ_API_KEY`) from [console.groq.com](https://console.groq.com).
- `groq-sdk` installed: `npm install groq-sdk`.
- A feature-flag mechanism (LaunchDarkly, env var, config service) exposing a
  `groq_migration_pct` value for gradual traffic shifting.
- The existing provider's key still available (`OPENAI_API_KEY` or equivalent)
  so you can run both providers side-by-side during the cutover.
- Node `>=18` if you use the `performance.now()` benchmark helper.

## Instructions

Steps 1-2 below are the essential skeleton — the two changes every migration
needs. Steps 3-7 (the provider abstraction, traffic shifting, scanner,
benchmark, and full compatibility matrix) are moved verbatim into the
reference files linked under Examples so this file stays scannable.

### Step 1: OpenAI to Groq Migration

The minimal change: swap the SDK import, client, and model ID. The response
shape is identical, so downstream code (`result.choices[0].message.content`)
is untouched.

```typescript
// BEFORE: OpenAI
import OpenAI from "openai";
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const result = await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello" }],
});

// AFTER: Groq (minimal changes)
import Groq from "groq-sdk";
const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });
const result = await groq.chat.completions.create({
  model: "llama-3.3-70b-versatile",  // or "llama-3.1-8b-instant"
  messages: [{ role: "user", content: "Hello" }],
});

// Same response shape: result.choices[0].message.content
```

### Step 2: Model ID Mapping

Centralize the OpenAI/Anthropic → Groq translation so a single map drives the
whole codebase and unknown models fall back to a safe default.

```typescript
// OpenAI → Groq model equivalents
const MODEL_MAP: Record<string, string> = {
  // OpenAI → Groq (quality equivalent)
  "gpt-4o":        "llama-3.3-70b-versatile",
  "gpt-4o-mini":   "llama-3.1-8b-instant",
  "gpt-4-turbo":   "llama-3.3-70b-versatile",
  "gpt-3.5-turbo": "llama-3.1-8b-instant",

  // Anthropic → Groq (approximate)
  "claude-3-5-sonnet": "llama-3.3-70b-versatile",
  "claude-3-haiku":    "llama-3.1-8b-instant",
};

function migrateModelId(model: string): string {
  return MODEL_MAP[model] || "llama-3.3-70b-versatile";
}
```

### Steps 3-7: Zero-Downtime Rollout

Once Steps 1-2 compile, wrap both providers in a common interface and shift
traffic gradually. The full code lives in the references:

- **Step 3 — Provider abstraction layer** and **Step 4 — feature-flag traffic
  shifting**: [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-migration-deep-dive/references/implementation.md).
- **Step 5 — automated migration scanner** (sizes the migration before you
  start) and the **rollback plan**: [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-migration-deep-dive/references/implementation.md).
- **Step 6 — comparison benchmark** and **Step 7 — the OpenAI↔Groq
  compatibility matrix**: [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-migration-deep-dive/references/examples.md).

## Output

Running this skill's workflow produces:

- A migration assessment printout from the scanner (Step 5): OpenAI import
  count, the distinct `gpt-*` model IDs in use, any OpenAI-only features
  (embeddings/images/fine-tuning) that block a clean cutover, and the number
  of API-key references to update.
- A provider-agnostic `LLMProvider` layer with `GroqProvider` and
  `OpenAIProvider` implementations both live behind one `getProvider()` call.
- A benchmark table per prompt: Groq vs OpenAI latency in ms, token counts,
  and the measured speedup factor.
- A `groq_migration_pct` feature flag driving the canary → 100% ramp, with a
  one-flag rollback to 0%.

## Error Handling

| Issue | Cause | Solution |
|-------|-------|----------|
| Quality regression | Different model strengths | Tune system prompts for Llama models |
| Missing features | Groq doesn't have embeddings/images | Keep OpenAI for those features |
| Rate limits | Different limits than OpenAI | Configure per-model rate limits |
| Cost increase | Different pricing structure | Route simple tasks to 8B model |

## Examples

- **Full provider abstraction + traffic shifting + scanner + rollback**:
  [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-migration-deep-dive/references/implementation.md) — the complete
  Step 3-5 code plus the rollback procedure.
- **Benchmark harness + compatibility matrix**:
  [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-migration-deep-dive/references/examples.md) — the side-by-side
  quality/speed benchmark and the full OpenAI↔Groq feature table.

## Resources

- [Groq Quickstart](https://console.groq.com/docs/quickstart)
- [Groq Models](https://console.groq.com/docs/models)
- [Groq API Reference](https://console.groq.com/docs/api-reference)
- [groq-sdk npm](https://www.npmjs.com/package/groq-sdk)

## Next Steps

For ongoing SDK version upgrades between Groq model generations, see the
companion `groq-upgrade-migration` skill in this pack.
