Skip to content

Examples and guides for using the OpenAI API

Update Skills API Cookbook for Astra and restore its listing (#3112)

Konstantine Kahadze263b2d5b7b63
diff --git a/examples/skills_in_api.ipynb b/examples/skills_in_api.ipynb
index 9b73cddf..8126f429 100644
--- a/examples/skills_in_api.ipynb
+++ b/examples/skills_in_api.ipynb
@@ -11,7 +11,7 @@
"source": [
"# Skills in OpenAI API\n",
"\n",
- "Upload, manage, and attach reusable skills to hosted environments. Agent Skills let you upload and reuse versioned bundles of files in hosted and local shell environments. For the full reference, see the [Skills documentation](https://developers.openai.com/api/docs/guides/tools-skills)."
+ "Package a CSV analysis workflow as a skill, upload it, and run it with GPT-6 Astra in hosted shell. You can also expose the same files to a local shell runtime. For the full reference, see the [Skills documentation](https://developers.openai.com/api/docs/guides/tools-skills)."
]
},
{
@@ -41,9 +41,11 @@
"\n",
"\n",
"- The service uploads and unzips skills into the runtime\n",
- "- The service reads `SKILL.md` frontmatter (name/description), then adds each skill’s `name`, `description`, and `path` to the hidden system prompt context, which lets the model know the skill exists\n",
+ "- The service reads `SKILL.md` frontmatter (name/description), then adds each skill’s `name`, `description`, and `path` to user prompt context, which lets the model know the skill exists\n",
"- If the model decides to invoke a skill, it uses the `path` to read `SKILL.md`, then explores files and executes scripts via the shell tool\n",
"\n",
+ "Skill instructions have the same priority as other user-provided instructions.\n",
+ "\n",
"Skills are for procedures: repeatable workflows where the _how_ matters (steps, branching logic, formatting rules, scripts). Skills are useful for when you want your procedure:\n",
"\n",
"- Reused across prompts/agents\n",
@@ -260,11 +262,13 @@
"id": "54e51104",
"metadata": {},
"source": [
- "```\n",
- "curl -X POST 'https://api.openai.com/v1/skills' \\\n",
+ "```bash\n",
+ "curl --fail-with-body 'https://api.openai.com/v1/skills' \\\n",
" -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n",
" -F 'files[]=@./csv_insights_skill/SKILL.md;filename=csv_insights_skill/SKILL.md;type=text/markdown' \\\n",
- " -F 'files[]=@./csv_insights_skill/calculate.py;filename=csv_insights_skill/calculate.py;type=text/plain'\n",
+ " -F 'files[]=@./csv_insights_skill/run.py;filename=csv_insights_skill/run.py;type=text/plain' \\\n",
+ " -F 'files[]=@./csv_insights_skill/requirements.txt;filename=csv_insights_skill/requirements.txt;type=text/plain' \\\n",
+ " -F 'files[]=@./csv_insights_skill/assets/example.csv;filename=csv_insights_skill/assets/example.csv;type=text/csv'\n",
"```"
]
},
@@ -281,7 +285,7 @@
" -F 'files=@./csv_insights_skill.zip;type=application/zip'\n",
"```\n",
"\n",
- "If you hit server errors, **zip locally and upload the zip**. We ran into this internally and found this to be a practical workaround.\n",
+ "Use one upload method per skill. A zip keeps the instructions, script, dependencies, and sample input together.\n",
"\n"
]
},
@@ -306,7 +310,7 @@
}
},
"source": [
- "A skill returns identifiers and version pointers (e.g., default, latest). Version pointers show up in platform changes and tests."
+ "The response includes the skill `id`, `default_version`, and `latest_version`. Save the `id` and a version to attach the uploaded skill to hosted shell."
]
},
{
@@ -320,20 +324,12 @@
"source": [
"## Mounting skills into execution\n",
"\n",
- "Models use skills via the shell and container. To use skills in the Responses API, attach them to the shell tool with `tools[].environment.skills`.\n",
+ "To use skills in the Responses API, attach them to the shell tool with `tools[].environment.skills`.\n",
"\n",
"### How to reference skills\n",
"\n",
- "Specify the environment, either hosted or local shell.\n",
- "**Hosted vs. local**\n",
- "\n",
- "- Hosted shell: `environment.type=\"container_auto\"`\n",
- "- Local shell: `environment.type=\"local\"`\n",
- "\n",
- "**Skills can be referenced as**:\n",
- "\n",
- "- `skill_reference` (by `skill_id`, optionally with `version` or `\"latest\"`)\n",
- "- `inline` (base64 zip bundle) when you don’t want to create a hosted skill"
+ "- **Hosted shell** (`environment.type=\"container_auto\"`): use `skill_reference` with a `skill_id` and optional `version`, or an `inline` base64 zip bundle.\n",
+ "- **Local shell** (`environment.type=\"local\"`): provide `name`, `description`, and `path` for files available in your runtime. Local shell does not accept hosted `skill_reference` attachments. Your application executes the requested commands and returns their outputs."
]
},
{
@@ -345,7 +341,13 @@
}
},
"source": [
- "## Runnable example: `csv_insights_skill` Skill"
+ "## Runnable example: `csv_insights_skill` Skill\n",
+ "\n",
+ "This walkthrough creates files on disk and then runs Python snippets; it is not a notebook to execute with **Run All**. Save the script below as `csv_insights_skill/run.py`.\n",
+ "\n",
+ "Prerequisites: Python 3.10 or later, `curl`, `zip`, and an `OPENAI_API_KEY` environment variable for a project with access to `gpt-6-astra` and hosted shell. Install the current Python SDK with `python -m pip install --upgrade openai`.\n",
+ "\n",
+ "The upload commands create a skill in your API project. Responses API calls incur [model and container charges](https://developers.openai.com/api/docs/pricing). The Python API examples are disabled unless you set `RUN_SKILLS_API=1`. Run the local checks first, then opt in when you are ready to make API requests."
]
},
{
@@ -357,15 +359,38 @@
}
},
"source": [
- "**1) Create the skill folder.**\n",
+ "**1) Create the skill folder and sample input.**\n",
"\n",
+ "```bash\n",
+ "mkdir -p csv_insights_skill/assets\n",
"```\n",
+ "\n",
+ "The finished folder should contain:\n",
+ "\n",
+ "```text\n",
"csv_insights_skill/\n",
"├── SKILL.md\n",
"├── requirements.txt\n",
"├── run.py\n",
"└── assets/\n",
" └── example.csv\n",
+ "```\n",
+ "\n",
+ "Save these dependencies as `csv_insights_skill/requirements.txt`. `tabulate` is required by pandas' `to_markdown()` method.\n",
+ "\n",
+ "```text\n",
+ "pandas\n",
+ "matplotlib\n",
+ "tabulate\n",
+ "```\n",
+ "\n",
+ "Save this synthetic input as `csv_insights_skill/assets/example.csv`:\n",
+ "\n",
+ "```csv\n",
+ "quantity,price,category\n",
+ "2,10,books\n",
+ "3,15,games\n",
+ ",20,books\n",
"```\n"
]
},
@@ -410,13 +435,19 @@
"\n",
"## Outputs\n",
"- `output/report.md`\n",
- "- `output/plot.png`\n",
+ "- `output/plot.png` (when the CSV has a numeric column)\n",
"\n",
"## How to run\n",
"\n",
- "python -m pip install -r requirements.txt\n",
+ "Run from the directory containing this SKILL.md. The environment must have\n",
+ "pandas, matplotlib, and tabulate installed. If a dependency is unavailable,\n",
+ "report it rather than attempting an unapproved network install.\n",
+ "\n",
"python run.py --input assets/example.csv --outdir output\n",
"\n",
+ "Use the output directory requested by the user when one is provided.\n",
+ "Check that report.md exists and that plot.png exists for numeric input.\n",
+ "\n",
"```"
]
},
@@ -508,7 +539,18 @@
"id": "fa6ef039",
"metadata": {},
"source": [
- "**4) Zip it (recommended)**"
+ "**4) Test locally, then zip the skill.**\n",
+ "\n",
+ "From the directory containing `csv_insights_skill`, install dependencies and run the script:\n",
+ "\n",
+ "```bash\n",
+ "python -m pip install -r csv_insights_skill/requirements.txt\n",
+ "python csv_insights_skill/run.py --input csv_insights_skill/assets/example.csv --outdir local-output\n",
+ "```\n",
+ "\n",
+ "`local-output/report.md` should report three rows, three columns, and one missing `quantity` value. `local-output/plot.png` should contain a histogram of `quantity`.\n",
+ "\n",
+ "Package only the skill files, not the generated output:"
]
},
{
@@ -516,8 +558,8 @@
"id": "c844695b",
"metadata": {},
"source": [
- "```\n",
- "zip -r csv_insights_skill.zip csv_insights_skill\n",
+ "```bash\n",
+ "zip -r csv_insights_skill.zip csv_insights_skill/SKILL.md csv_insights_skill/requirements.txt csv_insights_skill/run.py csv_insights_skill/assets\n",
"```"
]
},
@@ -526,12 +568,15 @@
"id": "90ad52c8",
"metadata": {},
"source": [
- "**5) Upload the skill**\n",
+ "**5) Upload the skill (live API request).**\n",
"\n",
- "```\n",
- "curl -X POST 'https://api.openai.com/v1/skills' \\\n",
+ "Run this command only when you are ready to create the skill. It saves the response to `skill.json` for the next step.\n",
+ "\n",
+ "```bash\n",
+ "curl --fail-with-body 'https://api.openai.com/v1/skills' \\\n",
" -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n",
- " -F 'files=@./csv_insights_skill.zip;type=application/zip'\n",
+ " -F 'files=@./csv_insights_skill.zip;type=application/zip' \\\n",
+ " -o skill.json\n",
"```"
]
},
@@ -540,12 +585,11 @@
"id": "07085491",
"metadata": {},
"source": [
- "**6) Run the skill via the API (hosted shell pattern)**\n",
- "\n",
+ "**6) Run the skill via hosted shell (live API request).**\n",
"\n",
- "This follows the flow: create skill → call Responses API with the shell tool, with `environment.skills` referencing the skill\n",
+ "Set `RUN_SKILLS_API=1`, then run this snippet from the same directory as `skill.json`. It pins the uploaded skill's default version and analyzes the CSV bundled inside the skill. No separate CSV upload is needed.\n",
"\n",
- "Conceptually:\n"
+ "Hosted shell uses its installed dependencies; outbound network access is disabled by default. The skill reports missing dependencies rather than enabling network access automatically. Save downloadable artifacts under `/mnt/data`, as described in the [Shell guide](https://developers.openai.com/api/docs/guides/tools-shell#hosted-runtime-details)."
]
},
{
@@ -555,25 +599,41 @@
"metadata": {},
"outputs": [],
"source": [
- "from openai import OpenAI\n",
- "client = OpenAI()\n",
+ "import json\n",
+ "import os\n",
+ "from pathlib import Path\n",
"\n",
- "response = client.responses.create(\n",
- " model=\"gpt-5.2\",\n",
- " tools=[{\n",
- " \"type\": \"shell\",\n",
- " \"environment\": {\n",
- " \"type\": \"container_auto\",\n",
- " \"skills\": [\n",
- " {\"type\": \"skill_reference\", \"skill_id\": \"<skill_id>\"},\n",
- " {\"type\": \"skill_reference\", \"skill_id\": \"<skill_id>\", \"version\": 2},\n",
- " ],\n",
- " },\n",
- " }],\n",
- " input=\"Use the skills to analyze the uploaded CSV and write outputs to /mnt/output.\"\n",
- ")\n",
+ "from openai import OpenAI\n",
"\n",
- "print(response.output_text)"
+ "if os.environ.get(\"RUN_SKILLS_API\") == \"1\":\n",
+ " client = OpenAI()\n",
+ " skill = json.loads(Path(\"skill.json\").read_text())\n",
+ " response = client.responses.create(\n",
+ " model=\"gpt-6-astra\",\n",
+ " tools=[\n",
+ " {\n",
+ " \"type\": \"shell\",\n",
+ " \"environment\": {\n",
+ " \"type\": \"container_auto\",\n",
+ " \"skills\": [\n",
+ " {\n",
+ " \"type\": \"skill_reference\",\n",
+ " \"skill_id\": skill[\"id\"],\n",
+ " \"version\": str(skill[\"default_version\"]),\n",
+ " }\n",
+ " ],\n",
+ " },\n",
+ " }\n",
+ " ],\n",
+ " input=(\n",
+ " \"Use the csv-insights skill to analyze its bundled assets/example.csv. \"\n",
+ " \"Run the skill's run.py and write outputs to /mnt/data/csv-insights-output. \"\n",
+ " \"Verify the row count and missing values, and link to report.md and plot.png.\"\n",
+ " ),\n",
+ " )\n",
+ " print(response.output_text)\n",
+ "else:\n",
+ " print(\"Skipped live API request. Set RUN_SKILLS_API=1 to run.\")\n"
]
},
{
@@ -581,11 +641,11 @@
"id": "c926fc47",
"metadata": {},
"source": [
- "**7) Use this skill via the API (local container pattern)**\n",
+ "**7) Request a local shell call (optional, live API request).**\n",
"\n",
- "Skills also work with local shell mode. The skill selection and prompt behavior are the same as hosted shell mode, but command execution and filesystem access are still handled by your local runtime.\n",
+ "Local shell uses the files you created above, without uploading or referencing a hosted skill. Run this snippet from the directory containing `csv_insights_skill` in your execution environment.\n",
"\n",
- "Conceptually:"
+ "This snippet only requests and displays commands. It does not execute them or complete the analysis. To complete the workflow, your application must review and execute `shell_call` commands in a sandbox, capture stdout, stderr, and the exit outcome, and return `shell_call_output` with the matching `call_id`. Continue until the model returns its final answer. See [Local shell mode](https://developers.openai.com/api/docs/guides/tools-shell#local-shell-mode) for the execution loop and output format."
]
},
{
@@ -595,28 +655,45 @@
"metadata": {},
"outputs": [],
"source": [
- "from openai import OpenAI\n",
- "\n",
- "client = OpenAI()\n",
+ "import os\n",
+ "from pathlib import Path\n",
"\n",
- "response = client.responses.create(\n",
- " model=\"gpt-5.2\",\n",
- " tools=[\n",
- " {\n",
- " \"type\": \"shell\",\n",
- " \"environment\": {\n",
- " \"type\": \"local\",\n",
- " \"skills\": [\n",
- " {\"type\": \"skill_reference\", \"skill_id\": \"<skill_id>\"},\n",
- " {\"type\": \"skill_reference\", \"skill_id\": \"<skill_id>\", \"version\": 2},\n",
- " ],\n",
- " },\n",
- " }\n",
- " ],\n",
- " input=\"Use the configured skills and run locally to summarize today's CSV reports in this repo.\",\n",
- ")\n",
+ "from openai import OpenAI\n",
"\n",
- "print(response.output_text)"
+ "if os.environ.get(\"RUN_SKILLS_API\") == \"1\":\n",
+ " client = OpenAI()\n",
+ " skill_path = Path(\"csv_insights_skill\").resolve()\n",
+ " response = client.responses.create(\n",
+ " model=\"gpt-6-astra\",\n",
+ " tools=[\n",
+ " {\n",
+ " \"type\": \"shell\",\n",
+ " \"environment\": {\n",
+ " \"type\": \"local\",\n",
+ " \"skills\": [\n",
+ " {\n",
+ " \"name\": \"csv-insights\",\n",
+ " \"description\": (\n",
+ " \"Summarize a CSV, compute basic stats, and produce \"\n",
+ " \"a markdown report + a plot image.\"\n",
+ " ),\n",
+ " \"path\": str(skill_path),\n",
+ " }\n",
+ " ],\n",
+ " },\n",
+ " }\n",
+ " ],\n",
+ " input=(\n",
+ " \"Use the csv-insights skill to analyze its bundled assets/example.csv \"\n",
+ " \"and write outputs to local-output.\"\n",
+ " ),\n",
+ " )\n",
+ " for item in response.output:\n",
+ " if item.type == \"shell_call\":\n",
+ " print(item.action.commands)\n",
+ " print(response.output_text)\n",
+ "else:\n",
+ " print(\"Skipped live API request. Set RUN_SKILLS_API=1 to run.\")\n"
]
},
{
@@ -651,9 +728,9 @@
"\n",
"**3) Version pin in production**\n",
"\n",
- "You want to be able to say, “Run this procedure version,” not, “Run whatever the latest is.” Skills are trending toward explicit versions (**default_version**, **latest_version**), and there’s active work on version creation endpoints.\n",
+ "You want to be able to say, “Run this procedure version,” not, “Run whatever the latest is.” Uploaded skills have **default_version** and **latest_version** pointers. Create new versions with `POST /v1/skills/{skill_id}/versions`; see [versioning and management](https://developers.openai.com/api/docs/guides/tools-skills#versioning-and-management).\n",
"\n",
- "* How to pin: `version: 2`\n",
+ "* How to pin: `version: \"2\"`\n",
"* How to float: `version: \"latest\"`\n",
"* What happens when omitted: defaults to `default_version`\n",
"\n",
@@ -668,7 +745,7 @@
"* Fails loudly with usage/errors\n",
"* Writes outputs to known file paths when needed\n",
"\n",
- "Add concrete templates and worked examples inside the skill (inputs → commands → expected outputs); they cost nothing on turns where the skill isn’t invoked. When examples are workflow-specific, prefer examples and templates in skills over system-level, few-shot prompting.\n",
+ "Add concrete templates and worked examples inside the skill (inputs → commands → expected outputs); the model reads these details when it invokes the skill, while discovery metadata remains part of the input context. When examples are workflow-specific, prefer examples and templates in skills over system-level, few-shot prompting.\n",
"\n",
"**5) Avoid duplicating skills in system prompts**\n",
"\n",
diff --git a/registry.yaml b/registry.yaml
index c0206992..6fdce235 100644
--- a/registry.yaml
+++ b/registry.yaml
@@ -3702,7 +3702,6 @@
- title: Skills in OpenAI API
path: examples/skills_in_api.ipynb
slug: skills-in-api
- archived: true
description: Cookbook for building skills with the OpenAI API.
date: 2026-02-10
authors: