Use AI models from GitHub Models in your workflows.
Create a workflow to use the AI inference action:
name: 'AI inference'
on: workflow_dispatch
jobs:
inference:
permissions:
models: read
runs-on: ubuntu-latest
steps:
- name: Test Local Action
id: inference
uses: actions/ai-inference@v1
with:
prompt: 'Hello!'
- name: Print Output
id: output
run: echo "${{ steps.inference.outputs.response }}"
You can also provide a prompt file instead of an inline prompt. The action
supports both plain text files and structured .prompt.yml files:
steps:
- name: Run AI Inference with Text File
id: inference
uses: actions/ai-inference@v1
with:
prompt-file: './path/to/prompt.txt'
For more advanced use cases, you can use structured .prompt.yml files that
support templating, custom models, and JSON schema responses:
steps:
- name: Run AI Inference with Prompt YAML
id: inference
uses: actions/ai-inference@v1
with:
prompt-file: './.github/prompts/sample.prompt.yml'
input: |
var1: hello
var2: ${{ steps.some-step.outputs.output }}
var3: |
Lorem Ipsum
Hello World
file_input: |
var4: ./path/to/long-text.txt
var5: ./path/to/config.json
messages:
- role: system
content: Be as concise as possible
- role: user
content: 'Compare {{a}} and {{b}}, please'
model: openai/gpt-4o
messages:
- role: system
content: You are a helpful assistant that describes animals using JSON format
- role: user
content: |-
Describe a {{animal}}
Use JSON format as specified in the response schema
model: openai/gpt-4o
responseFormat: json_schema
jsonSchema: |-
{
"name": "describe_animal",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the animal"
},
"habitat": {
"type": "string",
"description": "The habitat the animal lives in"
}
},
"additionalProperties": false,
"required": [
"name",
"habitat"
]
}
}
Variables in prompt.yml files are templated using {{variable}} format and are
supplied via the input parameter in YAML format. Additionally, you can
provide file-based variables via file_input, where each key maps to a file
path.
You can specify model parameters directly in your .prompt.yml files using the
modelParameters key:
messages:
- role: system
content: Be as concise as possible
- role: user
content: 'Compare {{a}} and {{b}}, please'
model: openai/gpt-4o
modelParameters:
maxCompletionTokens: 500
temperature: 0.7
| Key | Type | Description |
|---|---|---|
maxCompletionTokens |
number | The maximum number of tokens to generate |
maxTokens |
number | The maximum number of tokens to generate (deprecated) |
temperature |
number | The sampling temperature to use (0-1) |
topP |
number | The nucleus sampling parameter to use (0-1) |
![Note] Parameters set in
modelParameterstake precedence over the corresponding action inputs.
In addition to the regular prompt, you can provide a system prompt file instead of an inline system prompt:
steps:
- name: Run AI Inference with System Prompt File
id: inference
uses: actions/ai-inference@v1
with:
prompt: 'Hello!'
system-prompt-file: './path/to/system-prompt.txt'
This can be useful when model response exceeds actions output limit
steps:
- name: Test Local Action
id: inference
uses: actions/ai-inference@v1
with:
prompt: 'Hello!'
- name: Use Response File
run: |
echo "Response saved to: ${{ steps.inference.outputs.response-file }}"
cat "${{ steps.inference.outputs.response-file }}"
You can include custom HTTP headers in your API requests, which is useful for integrating with API Management platforms, adding tracking information, or routing requests through custom gateways.
steps:
- name: AI Inference with Azure APIM
id: inference
uses: actions/ai-inference@v1
with:
prompt: 'Analyze this code for security issues...'
endpoint: ${{ secrets.APIM_ENDPOINT }}
token: ${{ secrets.APIM_KEY }}
custom-headers: |
Ocp-Apim-Subscription-Key: ${{ secrets.APIM_SUBSCRIPTION_KEY }}
serviceName: code-review-workflow
env: production
team: security
computer: github-actions
steps:
- name: AI Inference with Custom Headers
id: inference
uses: actions/ai-inference@v1
with:
prompt: 'Hello!'
custom-headers: '{"X-Custom-Header": "value", "X-Team": "engineering", "X-Request-ID": "${{ github.run_id }}"}'
Header name requirements: Header names must follow the HTTP token syntax defined in RFC 7230 (which permits underscores). For maximum compatibility with intermediaries and tooling, we recommend using only alphanumeric characters and hyphens.
Security note: Always use GitHub secrets for sensitive header values like API keys, tokens, or passwords. The action automatically masks common sensitive headers (containing key, token, secret, password, or authorization) in logs.
By default the action calls the GitHub Models REST API. You can instead route inference through the GitHub Copilot CLI by setting provider: copilot.
Because the Copilot CLI is not pre-installed on GitHub-hosted runners, you'll need to install and authenticate it in earlier steps before invoking this action. The pattern follows the official GitHub Actions docs:
name: 'AI inference (Copilot)'
on: workflow_dispatch
jobs:
inference:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
- name: Install Copilot CLI
run: npm install -g @github/copilot
- name: Run AI Inference via Copilot
id: inference
uses: actions/ai-inference@v1
with:
prompt: 'Summarise the latest changes in this repo.'
provider: copilot
model: gpt-4.1 # any model the Copilot CLI accepts; omit to use the CLI default
env:
# Create a fine-grained PAT with the "Copilot Requests" permission and
# store it as a repository secret. See the docs linked above.
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_PAT }}
- run: echo "${{ steps.inference.outputs.response }}"
Notes when provider: copilot:
PATH (or pass copilot-cli-path) and authenticated via COPILOT_GITHUB_TOKEN (or another env var Copilot CLI accepts) before this action runs.openai/gpt-4o) is a GitHub Models identifier and is not forwarded to Copilot. Set model: to a Copilot-compatible model (e.g. gpt-4.1, claude-sonnet-4.5) when you want to override the CLI default.enable-github-mcp, custom-headers, endpoint, and responseFormat / jsonSchema are ignored under this provider — Copilot has its own tools and configuration mechanism. Use copilot-allow-tools (e.g. shell(git:*),write) to opt in to specific Copilot tools.-p <prompt> -s --no-ask-user, so it never blocks on interactive prompts and stdout is just the model response.--allow-tool flags are passed unless you set copilot-allow-tools, so Copilot can't run shell commands, write files, or fetch URLs out of the box.This action supports read-only integration with the GitHub-hosted Model Context Protocol (MCP) server, which provides access to GitHub tools like repository management, issue tracking, and pull request operations.
You can authenticate the MCP server with either:
ghs_…) – short-lived, app-scoped tokenThe built-in
GITHUB_TOKENis not accepted by the MCP server. Using a GitHub App installation token is recommended in most CI environments because it is short-lived and least-privilege by design.
Set enable-github-mcp: true and provide a token via github-mcp-token.
steps:
- name: AI Inference with GitHub Tools
id: inference
uses: actions/ai-inference@v1.2
with:
prompt: 'List my open pull requests and create a summary'
enable-github-mcp: true
token: ${{ secrets.USER_PAT }} # or a ghs_ installation token
If you want, you can use separate tokens for the AI inference endpoint and the GitHub MCP server:
steps:
- name: AI Inference with Separate MCP Token
id: inference
uses: actions/ai-inference@v1.2
with:
prompt: 'List my open pull requests and create a summary'
enable-github-mcp: true
token: ${{ secrets.GITHUB_TOKEN }}
github-mcp-token: ${{ secrets.USER_PAT }} # or a ghs_ installation token
By default, the GitHub MCP server provides a standard set of tools (context, repos, issues, pull_requests, users). You can customize which toolsets are available by specifying the github-mcp-toolsets parameter:
steps:
- name: AI Inference with Custom Toolsets
id: inference
uses: actions/ai-inference@v2
with:
prompt: 'Analyze recent workflow runs and check security alerts'
enable-github-mcp: true
token: ${{ secrets.USER_PAT }}
github-mcp-toolsets: 'repos,issues,pull_requests,actions,code_security'
Available toolsets: See: Tool configuration
When MCP is enabled, the AI model will have access to GitHub tools and can perform actions like searching issues and PRs.
Various inputs are defined in action.yml to let you configure
the action:
| Name | Description | Default |
|---|---|---|
token |
Token to use for inference. Typically the GITHUB_TOKEN secret | github.token |
prompt |
The prompt to send to the model | N/A |
prompt-file |
Path to a file containing the prompt (supports .txt and .prompt.yml formats). If both prompt and prompt-file are provided, prompt-file takes precedence |
"" |
input |
Template variables in YAML format for .prompt.yml files (e.g., var1: value1 on separate lines) |
"" |
$ claude mcp add ai-inference \
-- python -m otcore.mcp_server <graph>