Medusa Api Routes logo

Medusa Api Routes

Organization
OrcaQubits
medusa-api-routes

Create custom Medusa v2 API routes — file-based routing, HTTP method exports, middleware configuration, Zod validators, authentication middleware, and additional-data pattern. Use when adding REST endpoints.

Overview

PublisherOrcaQubits
Repositoryagentic-commerce-skills-plugins
Skill namemedusa-api-routes
Stars
40
Forks
17
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by OrcaQubits on GitHub. Read the source before you install it.

Installation

Install the Medusa Api Routes AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/OrcaQubits/agentic-commerce-skills-plugins/tree/main/medusa-commerce/skills/medusa-api-routes
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/OrcaQubits/agentic-commerce-skills-plugins.git /tmp/agentic-commerce-skills-plugins
mkdir -p .claude/skills
cp -r /tmp/agentic-commerce-skills-plugins/medusa-commerce/skills/medusa-api-routes .claude/skills/medusa-api-routes
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Medusa Api Routes in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Medusa Api Routes on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Medusa Api Routes is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Medusa v2 Custom API Routes

Before writing code

Fetch live docs:

  1. Fetch https://docs.medusajs.com/learn/fundamentals/api-routes for API route overview
  2. Web-search site:docs.medusajs.com custom API route file convention for file-based routing
  3. Web-search site:docs.medusajs.com API route middleware for middleware configuration
  4. Web-search site:docs.medusajs.com API route validation zod for request validation
  5. Web-search site:docs.medusajs.com additional data API routes for the additional-data pattern

File-Based Routing

Medusa v2 uses a file-system router under src/api/:

File PathResulting Endpoint
src/api/store/custom/route.tsGET/POST /store/custom
src/api/admin/custom/route.tsGET/POST /admin/custom
src/api/store/custom/[id]/route.tsGET/POST /store/custom/:id
src/api/custom/route.tsGET/POST /custom (no auth prefix)

Conventions

  • File must be named route.ts (not index.ts)
  • Dynamic parameters use [param] folder syntax
  • The store/ prefix applies storefront authentication scope
  • The admin/ prefix applies admin authentication scope
  • Routes outside these prefixes have no default authentication

HTTP Method Exports

Each route.ts exports named functions matching HTTP methods:

Export NameHTTP Method
GETGET
POSTPOST
PUTPUT
PATCHPATCH
DELETEDELETE

Route Handler Skeleton

typescript
// src/api/store/custom/route.ts
// Fetch live docs for MedusaRequest/MedusaResponse types
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"

export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
  const service = req.scope.resolve("my-module")
  res.json({ items: await service.listMyEntities() })
}

Route with Dynamic Parameter

typescript
// src/api/store/custom/[id]/route.ts
// Fetch live docs for path parameter access
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
  const item = await req.scope.resolve("my-module").retrieveMyEntity(req.params.id)
  res.json({ item })
}

Request Validation with Zod

Medusa v2 uses Zod schemas for request body and query parameter validation:

Validation File Convention

Validation TargetFile
POST/PUT/PATCH bodyvalidators.ts in same directory as route.ts
Query parametersSame validators.ts file

Validator Skeleton

typescript
// src/api/store/custom/validators.ts
// Fetch live docs for Zod schema integration
import { z } from "zod"

export const PostStoreCustom = z.object({
  name: z.string(),
  description: z.string().optional(),
})

Validators are linked to routes via middleware configuration.

Middleware Configuration

All middleware is configured in src/api/middlewares.ts:

typescript
// src/api/middlewares.ts — Fetch live docs for defineMiddlewares API
import { defineMiddlewares, validateAndTransformBody } from "@medusajs/framework/http"
import { PostStoreCustom } from "./store/custom/validators"

export default defineMiddlewares({
  routes: [{ matcher: "/store/custom", method: "POST",
    middlewares: [validateAndTransformBody(PostStoreCustom)] }],
})

Built-in Middleware Utilities

UtilityPurpose
validateAndTransformBody(schema)Validate request body with Zod
validateAndTransformQuery(schema)Validate query parameters
authenticate("customer", ["session", "bearer"])Require customer auth
authenticate("user", ["session", "bearer"])Require admin auth

Authentication Middleware

Route PrefixDefault AuthCustom Auth Override
/admin/*Admin user requiredCan be loosened per route
/store/*Optional customer authCan require auth per route
/custom/*NoneMust add explicitly

Requiring Customer Authentication

typescript
// In middlewares.ts routes array
// Fetch live docs for authenticate() options
{
  matcher: "/store/custom/me",
  middlewares: [authenticate("customer", ["session", "bearer"])],
}

Additional Data Pattern

Medusa v2 supports passing extra data through built-in API routes to workflow hooks:

  • Client sends extra fields in the request body under additional_data
  • Validated by defining an additionalDataValidator in middleware
  • Received in workflow hooks as additional_data

This allows extending core commerce flows (e.g., adding custom fields to product creation) without overriding API routes.

Error Handling

Error TypeRecommended Approach
Validation errorHandled automatically by Zod middleware (400)
Not foundThrow MedusaError with NOT_FOUND type
UnauthorizedHandled by auth middleware (401)
Business logicThrow MedusaError with appropriate type
UnexpectedLet Medusa error handler return 500

Best Practices

  • Use file-based routing conventions -- do not register routes programmatically
  • Always validate request bodies with Zod schemas via validateAndTransformBody
  • Resolve services from req.scope -- never import services directly
  • Use the additional_data pattern to extend core routes instead of overriding them
  • Apply authenticate() middleware explicitly for routes requiring auth outside default scopes
  • Return consistent response shapes: { item } for single, { items, count, offset, limit } for lists
  • Keep route handlers thin -- delegate business logic to workflows or services

Fetch the Medusa API route documentation for exact file conventions, middleware utilities, and Zod integration patterns before implementing.

Frequently asked questions

What does the Medusa Api Routes AI skill do?

Create custom Medusa v2 API routes — file-based routing, HTTP method exports, middleware configuration, Zod validators, authentication middleware, and additional-data pattern. Use when adding REST endpoints.

Why use Medusa Api Routes on TypingMind?

Because you install it once and use it with any model. Medusa Api Routes is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Medusa Api Routes in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/OrcaQubits/agentic-commerce-skills-plugins/tree/main/medusa-commerce/skills/medusa-api-routes. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Medusa Api Routes?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Medusa Api Routes?

As many as you like. As long as a model supports skills, you can use Medusa Api Routes with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Medusa Api Routes AI skill free?

Yes. It is published on GitHub by OrcaQubits under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇