GitHub Action to interact with different AI model providers.
In order to use this action, you need to
name: Basic text generation example
on:
push:
branches:
- main
jobs:
generate-text:
runs-on: ubuntu-latest
steps:
- uses: vercel/ai-action@v2
id: prompt
with:
prompt: 'Why is the sky blue?'
model: 'openai/gpt5'
api-key: ${{ secrets.AI_GATEWAY_API_KEY }}
- run: echo ${{ steps.prompt.outputs.text }}
You can provide a system message to set the behavior or context for the AI model:
name: Text generation with system message
on:
push:
branches:
- main
jobs:
generate-text:
runs-on: ubuntu-latest
steps:
- uses: vercel/ai-action@v2
id: prompt
with:
system: 'You are a kindergarten teacher getting questions by 5 year old students'
prompt: 'Why is the sky blue?'
model: 'openai/gpt5'
api-key: ${{ secrets.AI_GATEWAY_API_KEY }}
- run: echo ${{ steps.prompt.outputs.text }}
When you provide a JSON schema, the action will generate structured data that conforms to your schema:
name: Structured data generation example
on:
push:
branches:
- main
jobs:
generate-recipe:
runs-on: ubuntu-latest
steps:
- uses: vercel/ai-action@v2
id: recipe
with:
prompt: 'Generate a lasagna recipe'
schema: |
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"recipe": {
"type": "object",
"properties": {
"name": {"type": "string"},
"ingredients": {
"type": "array",
"items": {"type": "string"}
},
"steps": {
"type": "array",
"items": {"type": "string"}
}
},
"required": ["name", "ingredients", "steps"],
"additionalProperties": false
}
},
"required": ["recipe"],
"additionalProperties": false
}
model: 'openai/gpt-4.1'
api-key: ${{ secrets.AI_GATEWAY_API_KEY }}
- name: Use structured output
run: |
echo "Generated recipe JSON:"
echo '${{ steps.recipe.outputs.json }}'
# Parse and use specific fields
echo "Recipe name: ${{ fromJson(steps.recipe.outputs.json).recipe.name }}"
Required. The input prompt to generate the text from.
Required. An API KEY for the AI Gateway.
Required. An identifier from the list of provider models supported by the AI Gateway: https://vercel.com/ai-gateway/models
Optional. A valid JSON Schema for structured output generation. When provided, the action will use generateObject
to generate structured JSON data that conforms to the schema. The schema should be a valid JSON Schema (draft 2020-12 or compatible).
Optional. A system message to set the behavior or context for the AI model. This is useful for defining the role, personality, or instructions for the AI assistant. The system message is supported by both generateText()
and generateObject()
methods.
The generated text by the model. When using structured generation with a schema, this contains the JSON string.
The generated JSON object when using structured generation with a schema. This output is only available when the schema
input is provided.
The action is utilizing the AI SDK to send requests to the AI Gateway.
- Text Generation: Uses
generateText()
for basic text generation - Structured Generation: Uses
generateObject()
when a JSON schema is provided, ensuring the output conforms to your specified structure