The Martian provider for the AI SDK contains language model support for the Martian API.
npm install @withmartian/ai-sdk-providerSet your API key (e.g. in .env):
MARTIAN_API_KEY=your_martian_api_key_hereimport { generateText } from "ai";
import { martianProvider } from "@withmartian/ai-sdk-provider";
const { text } = await generateText({
model: martianProvider("gpt-4o-mini"), // → "openai/gpt-4o-mini"
prompt: "Write a limerick about cats."
});
console.log(text);Tool calling:
import { generateText } from "ai";
import { martianProvider } from "@withmartian/ai-sdk-provider";
import { z } from "zod";
const { text, toolCalls } = await generateText({
model: martianProvider("anthropic/claude-sonnet-4-20250514"),
prompt: "What's the weather in San Francisco?",
tools: {
getWeather: {
description: "Get weather for a city",
inputSchema: z.object({ city: z.string() }),
execute: async ({ city }) => ({ city, temp: 60, conditions: "sunny" }),
},
},
maxSteps: 3,
});Advanced Generation:
import { generateText } from "ai";
import { martianProvider } from "@withmartian/ai-sdk-provider";
const { text, finishReason, usage } = await generateText({
model: martianProvider("google/gemini-2.0-flash"),
system: "You are a creative writing assistant.",
messages: [
{ role: "user", content: "Write a short story about an alien." },
{ role: "assistant", content: "Once upon a time, there was an alien from Mars..." },
{ role: "user", content: "Continue the story with a twist ending." },
],
temperature: 0.9,
topP: 0.95,
maxTokens: 800,
stopSequences: ["THE END", "---"],
});Structured outputs:
import { generateObject } from "ai";
import { martianProvider } from "@withmartian/ai-sdk-provider";
import { z } from "zod";
const { object } = await generateObject({
model: martianProvider("gpt-4o-mini"),
schema: z.object({
recipe: z.string(),
ingredients: z.array(z.string()),
steps: z.array(z.string()),
}),
prompt: "Generate a simple pasta recipe.",
});
console.log(object.recipe);
console.log(object.ingredients);import { createMartianProvider } from "@withmartian/ai-sdk-provider";
const martian = createMartianProvider({
apiKey: "your-api-key", // defaults to MARTIAN_API_KEY env var
baseURL: "https://...", // defaults to api.withmartian.com/v1
});- OpenAI-style ids are automatically prefixed with
openai/. - Already-namespaced ids (e.g.
anthropic/...) are passed through unchanged.
Please check out the Martian provider documentation for more information. See the Available Models section for a full list of supported models.
MIT