How to Use OpenAI in opencode
To use OpenAI in opencode, connect Spiral to opencode once, then ask for what you want in plain words. opencode can then reach all 51 OpenAI tools on Spiral, priced per run from one balance.
Prompts to try with OpenAI in opencode
Copy an example into opencode, or ask in your own words.
Generate a product photo with OpenAI: a matte black water bottle on wet slate, soft morning light, 1:1. Tell me the price first. Save the result in ./assets.
Make four logo concepts for a coffee brand called "Northline" with OpenAI.
Create a 16:9 hero image of a quiet mountain cabin at dusk with OpenAI.
Generate a 9:16 poster with OpenAI for a jazz night called "Blue Hour", deep navy and brass tones.
Generate a flat illustration of a team planning session with OpenAI for our blog header, 16:9.
How to set up OpenAI in opencode
Pick the way that suits you. Each takes about two minutes.
Use Spiral's MCP server
- Add the server
Leave out --global to add Spiral to the current project only. No header and no client ID or secret: opencode registers itself with Spiral.
opencode mcp add spiral --global --url https://api.spiral.ai/mcp
- Sign in
Your browser opens. Sign in to Spiral, pick the organization and click Authorize, then return to the terminal. No API key. Inside opencode, /mcps starts the same sign-in.
opencode mcp auth spiral
- Check it
Spiral shows as connected.
opencode mcp list
Use the Spiral skill
- Send opencode this message
Your agent reads Spiral's skill and sets itself up.
set up https://spiral.ai/SKILL.md
- Sign in or paste a key
Approve Spiral in the browser, or give the agent a key from the console.
Use the Spiral CLI
- Install and sign in
Installs the Spiral CLI, signs you in and adds its skill to your coding agents.
npx -y spiral-cli@latest init
Call the Spiral API
- Create an API key
In the console, under API keys.
- Run OpenAI
One request; the result comes back by polling or a webhook.
curl https://api.spiral.ai/v1/runs \ -H "Authorization: Bearer $SPIRAL_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d '{ "provider": "openai", "model": "gpt-image-2", "input": { "prompt": "A cute baby sea otter" } }'
Then paste one of the prompts above: opencode finds OpenAI on Spiral, shows the price and runs it.
OpenAI tools you can run in opencode
3Ready to run from opencode: today's price, with every fee included.
$0.274 per 1024×1024 image at high quality ($0.00775 low, $0.0686 medium). At high: $0.214 at 1536×1024 or 1024×1536, $0.198 at 1792×1024 or 1024×1792, $0.203 at 512×512, $0.186 at 256×256. Auto quality or size: the price of the one chosen for the request. Prompt: $6.50 per 1M tokens.
Up to $0.074628 per run at the default inputs. $2.275 per 1M input tokens, $0.2275 per 1M cached input tokens, $18.20 per 1M output tokens.
Up to $0.010662 per run at the default inputs. $0.325 per 1M input tokens, $0.0325 per 1M cached input tokens, $2.60 per 1M output tokens.
What can you do with OpenAI in opencode?
opencode can generate images with OpenAI right in your repository and save the results where you need them: as files in your project, in a script or in your build. One sign-in covers every tool, so your code stays free of provider SDKs and keys.
Product and ad images
Shots, banners and social posts at the exact size each channel needs.
Concepts and moodboards
Several directions in one prompt, priced before they run.
Assets for your build
Icons, hero images and placeholders saved straight into your project.
Blog and social headers
A header image for every post, in your brand's style.
UI placeholders
Realistic images for mockups and prototypes.
Localized creatives
The same ad in several languages and sizes.
More on OpenAI and opencode
Overview
OpenAI in other agents
More opencode guides
Questions about OpenAI in opencode
Can opencode use OpenAI?
Yes. Add Spiral to opencode as an MCP server, and opencode can find and run OpenAI like any built-in tool.
How much does OpenAI cost in opencode?
Each tool has its own price, for example GPT Image 2 Text to Image: $0.274 per 1024×1024 image at high quality ($0.00775 low, $0.0686 medium). At high: $0.214 at 1536×1024 or 1024×1536, $0.198 at 1792×1024 or 1024×1792, $0.203 at 512×512, $0.186 at 256×256. Auto quality or size: the price of the one chosen for the request. Prompt: $6.50 per 1M tokens; GPT-5.2: Up to $0.074628 per run at the default inputs. $2.275 per 1M input tokens, $0.2275 per 1M cached input tokens, $18.20 per 1M output tokens; GPT-5 Mini: Up to $0.010662 per run at the default inputs. $0.325 per 1M input tokens, $0.0325 per 1M cached input tokens, $2.60 per 1M output tokens. You pay per run from one Spiral balance, and failed runs are free.
Do I need an OpenAI account to use OpenAI in opencode?
No. Spiral runs OpenAI on its own OpenAI account. You sign in to Spiral once and never paste a key.
How long does it take to set up OpenAI in opencode?
About two minutes: add the server, then sign in, then check it.
Does opencode wait while OpenAI runs?
OpenAI runs in the background. opencode starts the run, checks on it and gives you the image when it's ready.
Which OpenAI tools can opencode use?
opencode can reach all 51 OpenAI tools on Spiral, covering LLM, image, and audio. Popular ones include GPT Image 2 · Text to Image, GPT-5.2, and GPT-5 Mini. Ask for one by name, or describe the task and opencode picks a fitting tool.
Can opencode compare OpenAI tools?
Yes. Ask opencode to run the same request on two OpenAI tools and show both results with what each cost. Each run is priced and billed on its own.
What happens if a OpenAI run fails in opencode?
It is not charged. Spiral holds the estimated price when the run starts and returns it to your balance if the run fails on Spiral's side or the provider's. opencode gets the error and can retry or try another tool.
Is there a OpenAI subscription or plan?
No. Spiral is pay as you go from one prepaid balance, with no plans or minimums, and credits never expire. Auto top-up keeps opencode from stopping when the balance runs low.
Start using OpenAI in opencode
One Spiral account for every tool your agent needs. No subscription; you pay per run.
Paste this into opencode:
set up https://spiral.ai/SKILL.md


