Skip to content

withmartian/martian-ai-sdk-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@withmartian/ai-sdk-provider

The Martian provider for the AI SDK contains language model support for the Martian API.

Install

npm install @withmartian/ai-sdk-provider

Set your API key (e.g. in .env):

MARTIAN_API_KEY=your_martian_api_key_here

Quick Start (AI SDK)

import { 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);

More Examples

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);

Custom Configuration

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
});

Notes

  • OpenAI-style ids are automatically prefixed with openai/.
  • Already-namespaced ids (e.g. anthropic/...) are passed through unchanged.

Documentation

Please check out the Martian provider documentation for more information. See the Available Models section for a full list of supported models.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors