agentleFS
Rikinshah787Rikinshah787/agent-skills-production-skills/skills/openai/SKILL.md

openai

Skill2 starsChanged 4 months agoMITView on GitHub

Use to build with OpenAI's Responses API for text, images, files, structured output, streaming, tools, and vector embeddings.

  • Reads credentials
  • Installs packages

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 6 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use when: adding generation, extraction, classification, vision, document analysis, or tool-calling workflows.

    line 22
  2. Distinctive:

    Use when: you need structured output or embeddings for search and recommendations.

    line 23
  3. Distinctive:

    Don't use for: deterministic business rules that ordinary code can implement more cheaply and reliably.

    line 24
  4. Distinctive:

    Use Structured Outputs instead of JSON mode when possible.

    line 82
  5. Distinctive:

    Use the same embedding model and dimensions for documents and queries.

    line 137
  6. Very specific:

    Never expose OPENAI_API_KEY in browser code, mobile apps, logs, or public environment variables.

    line 149
  7. Distinctive:

    Treat model output and tool arguments as untrusted input: validate, authorize, and constrain every side effect.

    line 150

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

OpenAI API - Skillship

Generate and analyze text, images, and files through the Responses API, with schema-safe output, typed streams, callable tools, and embeddings for semantic search.

🧭 When to use this skill

  • Use when: adding generation, extraction, classification, vision, document analysis, or tool-calling workflows.
  • Use when: you need structured output or embeddings for search and recommendations.
  • Don't use for: deterministic business rules that ordinary code can implement more cheaply and reliably.

⚡ Quickstart

1. Install

npm install openai

2. Configure (server only)

OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-5.6

The SDK reads OPENAI_API_KEY automatically.

3. Call the Responses API

import "server-only";
import OpenAI from "openai";

const openai = new OpenAI();

const response = await openai.responses.create({
  model: process.env.OPENAI_MODEL ?? "gpt-5.6",
  instructions: "Answer accurately and say when you do not know.",
  input: "Explain vector databases in two sentences.",
});

console.log(response.output_text);

🧩 Common recipes

Recipe: Structured output with Zod

npm install zod
import OpenAI from "openai";
import { zodTextFormat } from "openai/helpers/zod";
import { z } from "zod";

const Event = z.object({
  name: z.string(),
  date: z.string(),
  participants: z.array(z.string()),
});

const response = await openai.responses.parse({
  model: process.env.OPENAI_MODEL ?? "gpt-5.6",
  input: "Alice and Bob are attending the science fair on Friday.",
  text: { format: zodTextFormat(Event, "event") },
});

if (!response.output_parsed) throw new Error("No structured output returned");
console.log(response.output_parsed);

Use Structured Outputs instead of JSON mode when possible. Handle refusals and incomplete responses as separate outcomes rather than assuming every response matches the schema.

Recipe: Stream text deltas

const stream = await openai.responses.create({
  model: process.env.OPENAI_MODEL ?? "gpt-5.6",
  input: "Write a short launch announcement.",
  stream: true,
});

for await (const event of stream) {
  if (event.type === "response.output_text.delta") {
    process.stdout.write(event.delta);
  }
}

Common lifecycle events are response.created, response.output_text.delta, response.completed, and error.

Recipe: Let the model request one of your functions

const response = await openai.responses.create({
  model: process.env.OPENAI_MODEL ?? "gpt-5.6",
  input: "What is the weather in Paris?",
  tools: [{
    type: "function",
    name: "get_weather",
    description: "Get the current weather for a city and country.",
    strict: true,
    parameters: {
      type: "object",
      properties: { location: { type: "string" } },
      required: ["location"],
      additionalProperties: false,
    },
  }],
});

const call = response.output.find((item) => item.type === "function_call");
if (call?.type === "function_call") {
  const argumentsObject = JSON.parse(call.arguments);
  // Validate argumentsObject, authorize the action, execute it, then return a function_call_output.
}

Recipe: Create an embedding

const result = await openai.embeddings.create({
  model: "text-embedding-3-small",
  input: "Semantic search text",
  encoding_format: "float",
});

const vector = result.data[0].embedding; // 1,536 values by default

Use the same embedding model and dimensions for documents and queries. For large indexes, store vectors in a vector database and rank with cosine similarity.

🚀 Ship to production

  • API keys stay server-side and are scoped/rotated through project settings.
  • Model ID is configurable; pin a versioned model when reproducibility matters.
  • Timeouts, retries with exponential backoff, and rate-limit handling are implemented.
  • Token usage, latency, model errors, and request IDs are logged without sensitive prompts.
  • Structured outputs handle refusal, incomplete, and error states explicitly.
  • Evals cover representative inputs before prompt/model changes are released.

🔐 Security & secrets

  • Never expose OPENAI_API_KEY in browser code, mobile apps, logs, or public environment variables.
  • Treat model output and tool arguments as untrusted input: validate, authorize, and constrain every side effect.
  • Apply moderation and human approval where user-generated or high-impact content requires it; streaming is harder to moderate before display.

🐛 Common errors & fixes

SymptomLikely causeFix
401 Incorrect API keyMissing, revoked, or wrong-project keySet the server env var and verify project access
429 responseRate or spend limit reachedBack off with jitter, reduce concurrency, and inspect limits
Parsed output is emptyRefusal or incomplete responseInspect response status/content blocks before reading parsed data
Tool causes unsafe actionArguments trusted without checksValidate schema, authorize the user, and require confirmation
Vector search dimensions mismatchDifferent models/dimensions usedRe-embed documents and queries with identical settings

💰 Pricing gotchas

  • Generation is billed by tokens and some built-in tools have separate usage charges. Embeddings are billed by input tokens; monitor both request volume and payload size.

📚 Sources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.