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 }}
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).
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 the
generateText
function for basic text generation - Structured Generation: Uses the
generateObject
function when a JSON schema is provided, ensuring the output conforms to your specified structure