Skip to main content

Meta (Llama)

Use Meta’s Llama models via the official Llama API. Access Llama 3.3, Llama 4 Scout, Llama 4 Maverick, and more through Meta’s hosted inference endpoint. The Llama API exposes an OpenAI-compatible interface.

Setup

npm install openai

Factory

import { meta } from "@radaros/core";

const model = meta("Llama-4-Scout-17B-16E-Instruct");
modelId
string
required
Model ID (e.g., "Llama-3.3-70B-Instruct", "Llama-4-Scout-17B-16E-Instruct", "Llama-4-Maverick-17B-128E-Instruct-FP8").
config
MetaLlamaConfig
Optional { apiKey?, baseURL? }.

Supported Models

ModelDescriptionBest For
Llama-4-Maverick-17B-128E-Instruct-FP8Latest flagship, 128 experts MoEMaximum capability
Llama-4-Scout-17B-16E-InstructLatest scout model, 16 expertsGreat balance of speed and quality
Llama-3.3-70B-InstructProven large modelComplex reasoning, tool calling
Llama-3.1-8B-InstructFast, efficientSimple tasks, high throughput
See the full list at llama.developer.meta.com/docs/models.

Basic Example

import { Agent, meta } from "@radaros/core";

const agent = new Agent({
  name: "llama-agent",
  model: meta("Llama-4-Scout-17B-16E-Instruct"),
  instructions: "You are a helpful, harmless, and honest assistant.",
});

const result = await agent.run("Explain the difference between TCP and UDP.");
console.log(result.text);

Tool Calling

Llama 3.1+ and Llama 4 models support function calling:
import { Agent, meta, defineTool } from "@radaros/core";
import { z } from "zod";

const agent = new Agent({
  name: "tool-agent",
  model: meta("Llama-3.3-70B-Instruct"),
  tools: [
    defineTool({
      name: "calculate",
      description: "Evaluate a math expression",
      parameters: z.object({ expression: z.string() }),
      execute: async ({ expression }) => {
        try { return String(Function(`return ${expression}`)()); }
        catch { return "Error evaluating expression"; }
      },
    }),
  ],
});

const result = await agent.run("What is 2^16 + 3^10?");
console.log(result.text);

Multi-Modal (Llama 4)

Llama 4 models support image input:
import { Agent, meta, type ContentPart } from "@radaros/core";
import { readFileSync } from "node:fs";

const agent = new Agent({
  name: "vision-agent",
  model: meta("Llama-4-Scout-17B-16E-Instruct"),
  instructions: "Analyze images carefully.",
});

const imageData = readFileSync("photo.jpg").toString("base64");
const result = await agent.run([
  { type: "text", text: "Describe this image in detail." },
  { type: "image", data: imageData, mimeType: "image/jpeg" },
] as ContentPart[]);
console.log(result.text);

Full Example

import { Agent, meta, CostTracker, defineTool } from "@radaros/core";
import { z } from "zod";

const costTracker = new CostTracker({
  pricing: {
    "Llama-3.3-70B-Instruct": { promptPer1k: 0.00099, completionPer1k: 0.00099 },
    "Llama-4-Scout-17B-16E-Instruct": { promptPer1k: 0.00015, completionPer1k: 0.0006 },
  },
});

const agent = new Agent({
  name: "coding-assistant",
  model: meta("Llama-3.3-70B-Instruct"),
  instructions: "You are a senior software engineer. Help with code reviews and architecture.",
  tools: [
    defineTool({
      name: "readFile",
      description: "Read a file's contents",
      parameters: z.object({ path: z.string() }),
      execute: async ({ path }) => `// ${path}\nexport function main() { console.log("hello"); }`,
    }),
  ],
  costTracker,
});

const result = await agent.run("Review the main function in index.ts");
console.log(result.text);
console.log(`Cost: $${costTracker.getSummary().totalCost.toFixed(6)}`);

Running Llama Locally

You can also run Llama models locally via Ollama:
import { ollama } from "@radaros/core";

const model = ollama("llama3.1:70b");
See Ollama for local setup instructions.

Environment Variables

VariableDescription
LLAMA_API_KEYLlama API key

Cross-References