api-gateway-troubleshooting
Diagnoses failing requests and deployment errors on Google Cloud API Gateway. Use when calls through a gateway return 4xx or 5xx errors, including 429 and other quota errors, time out, or fail a CORS preflight; when `api-configs create` fails with a service account, concurrency, or limit error, or `
- 01GitHub stars
- 22.8K
- 02Installs
- New
- 03Files scanned
- 9
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 1f0b2b1a0b4f0f5e… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
API Gateway Troubleshooting
Use this skill to find out why requests to a deployed Google Cloud API Gateway fail and how to fix them. Work only from three sources of evidence:
- Public Google Cloud documentation, linked from this skill.
- The user's own project, read with the user's own credentials.
- Files and output that the user provides, such as an OpenAPI document, an error response, or a pasted log entry.
Scope
This skill covers only Google Cloud API Gateway. If the question is about Apigee, Cloud Endpoints, or GKE Gateway API, reply that this skill covers only Google Cloud API Gateway, and don't run its steps or commands.
Usage Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read and follow the instructions in
Usage Attribution.
Ground rules
| Rule | Why |
|---|---|
Stay read-only until the user approves a change. While you diagnose, run only list, describe, get-iam-policy, and logging read commands, plus nslookup and curl GET requests to a path that's safe to call. | Gateways serve production traffic, and the quota metrics and limits of the most recently created API config apply to every gateway of the API. |
Before any change, show the exact command, what it changes, and how to undo it, then wait for an explicit yes. Changes include IAM grants, api-configs create, gateways update, Cloud Run ingress changes, and gcloud services enable. | The user owns the project and the change. |
Never fix a 401 or 403 by making a backend public (--allow-unauthenticated, --no-invoker-iam-check, allUsers) or by granting a basic role such as Editor. | Grant the gateway's service account the invoker role on the one backend instead, which keeps least privilege. |
Keep every log read bounded: filter on the gateway, set --freshness or a timestamp window, and set --limit. | Unbounded reads are slow and pull in caller data that the diagnosis doesn't need. |
| Redact API keys, bearer tokens, and JWTs before you show log entries, commands, or files. | Request logs and pasted output can contain credentials. |
| Base every limit, default, and error meaning on a linked public doc or on output from the user's project. If neither explains the problem, say so and escalate. | Guessing about undocumented behavior leads to wrong fixes. |
Use the user's existing gcloud login. Never ask for passwords, API key values, or service account key files. | Credentials don't belong in a chat transcript. |
| For Preview features (streaming, MCP, model routing), check the release notes before answering. | Preview behavior changes between releases. |
Prerequisites
- Google Cloud CLI. Use a recent
gcloud(the commands here were checked with version 591.0.0); see Install the gcloud CLI. Don't install or update software without the user's approval. Ifgcloudisn't available or the user says not to run commands, work in evidence mode: give the user the read-only commands to run, and diagnose from the output, response bodies, and log entries they paste. - Authentication. Use the user's existing
gcloud auth loginsession; this skill doesn't need application-default credentials. - Project. Ask which project hosts the gateway and pass
--project={project_id}on every command. Don't rungcloud config set, because it changes the user's environment. This skill troubleshoots existing gateways and never creates projects. - Billing. The project needs an active billing account even when usage stays in the free tier; see API Gateway pricing.
- APIs. API Gateway requires
apigateway.googleapis.com,servicemanagement.googleapis.com, andservicecontrol.googleapis.com. A gateway can keep responding while one of them is missing, and its logs then stay empty, so check withgcloud services list --enabled --project={project_id}. Enabling a missing API is a change that needs approval. - IAM roles for diagnosis (read-only):
roles/apigateway.viewer,roles/logging.viewer,roles/serviceusage.serviceUsageViewer, androles/iam.serviceAccountViewer(to check the gateway's service account). For Cloud Run backends, addroles/run.viewer; to trace a custom domain through its load balancer, addroles/compute.viewer; to check an API key's project,roles/serviceusage.serviceUsageVieweris also needed there. - IAM roles for fixes (only after approval):
roles/apigateway.admin;roles/iam.serviceAccountUseron the gateway's service account, because creating or updating an API config or a gateway requiresiam.serviceAccounts.actAs;roles/run.adminto change a Cloud Run service's IAM policy or ingress;roles/serviceusage.serviceUsageAdminto enable an API or a managed service, plusroles/servicemanagement.serviceConsumeron the API's managed service to enable it in another project; androles/iam.serviceAccountAdminto re-enable a disabled service account. - Region. Gateways are regional. Use the region that
gateways listreports. When a fix needs a new gateway, create it in the original gateway's region, or inus-central1if the user has no preference; see API Gateway deployment model and Cloud locations.
Workflow
Copy this checklist into your notes and tick it off as you go:
- [ ] 1. Context collected
- [ ] 2. Gateway identified by defaultHostname
- [ ] 3. Expected or transient states ruled out
- [ ] 4. Gateway log entry read (bounded query)
- [ ] 5. One branch chosen from the classification table
- [ ] 6. Root cause stated with redacted evidence and a doc link
- [ ] 7. Fix proposed, approved, and applied (or handed to the user)
- [ ] 8. Fix verified
- [ ] 9. Escalated, if the evidence points to Google Cloud
1. Collect context
Extract these from the conversation first, and ask only for what's missing:
| Needed | Why |
|---|---|
{project_id} of the gateway | Every command is scoped to it. |
Failing URL (host and path) or {gateway_id} and {region} | Identifies the gateway. |
| HTTP method, status code, and response body | Separates gateway errors from backend errors. |
| Approximate time of the failure, in UTC | Bounds the log query. |
| What changed recently (new API config, IAM, backend deploy, DNS) | Recent changes are the first place to look. |
| Authentication used by the caller (API key, JWT, none) | Selects the auth branch. |
If the project or the host is unknown, stop and ask before you run any
gcloud command. Don't guess project IDs, and don't use the active gcloud
project instead.
2. Identify the gateway
List the project's gateways:
gcloud api-gateway gateways list --project={project_id} \
--format="table(name.basename():label=GATEWAY,name.segment(3):label=REGION,defaultHostname,state,apiConfig)"
Match the request host against defaultHostname. Don't decide from the URL
suffix: a gateway's hostname can use either of two gateway.dev formats or,
for older streaming and model-routing gateways, a run.app format. Don't
guess the owning project from numbers in the hostname either; list the
gateways in the project the user names. A custom domain points at a load
balancer whose serverless NEG targets the gateway. See
references/triage-and-logs.md for the
hostname formats and how to trace a custom domain.
If no gateway in the project matches, confirm the product before going on (see Scope).
Then read the gateway's details, including its API config and streaming mode:
gcloud api-gateway gateways describe {gateway_id} \
--location={region} --project={project_id}
3. Rule out expected and transient states
- Gateway
stateisn'tACTIVE:CREATINGorUPDATINGmeans an operation is still running, so wait and check again.FAILEDmeans creation failed; read the error of the failed operation.DELETINGmeans the gateway is being removed. - API config just created: creating a complex API config can take up to ten minutes, and only one config can be created for an API at a time.
- First requests after an idle period: API Gateway has cold-start latency.
- Google Cloud incident: check the Service Health dashboard.
4. Read the gateway log entry
Use a bounded query that prints only the fields you need. Replace
{status_code} with the status the caller saw:
gcloud logging read 'resource.type="apigateway.googleapis.com/Gateway" AND resource.labels.gateway_id="{gateway_id}" AND resource.labels.location="{region}" AND httpRequest.status={status_code}' \
--project={project_id} --freshness=1h --limit=20 \
--format="json(timestamp,httpRequest.status,httpRequest.latency,httpRequest.requestUrl,jsonPayload.responseDetails,jsonPayload.apiConfig,jsonPayload.apiMethod)"
If you know the failure time, replace --freshness with a
timestamp>="{start_utc}" AND timestamp<="{end_utc}" filter that spans about
30 minutes around it. Read httpRequest.status, httpRequest.requestUrl,
jsonPayload.responseDetails, jsonPayload.apiConfig, and
jsonPayload.apiMethod. Keep the --format field list, because a full entry
can contain the caller's credentials, and redact credentials before you quote
any field, including a key query parameter in httpRequest.requestUrl.
To compare API configs, compare only the apis/{api_id}/configs/{config_id}
part: the same config can appear as a full resource name
(//apigateway.googleapis.com/projects/...) and with either the project
number or the project ID.
jsonPayload.responseDetails decides the branch: via_upstream means the
backend produced the response; any other value means the gateway produced it.
The troubleshooting page explains via_upstream and
service_control_quota_error, and the model routing page explains the
model_router_* values that model-routing gateways log. Quote any other value
as-is, and don't explain how the gateway works internally.
5. Classify and follow one branch
Pick the first row that matches, and load only the reference file it names.
| What you see | Likely cause | Reference |
|---|---|---|
401 or 403 with via_upstream | The backend rejected the gateway: invoker role, audience, or deleted service account | auth-errors.md |
A 4xx produced by the gateway whose body names a credential problem (for example UNAUTHENTICATED) | The API key or JWT was rejected; quote the body | auth-errors.md |
500 with no gateway log entry, after log exclusions and a wrong scope are ruled out | The gateway's service account may be deleted or disabled | auth-errors.md |
500 with service_control_quota_error | Quota metric missing from the newest API config | config-deployment-errors.md |
429 with service_control_quota_error | The caller exceeded the API's quota | limits-and-escalation.md |
404, 502, 503, or 504, an oversized request, or a timeout | Routing, backend errors, size limits, or the deadline. The docs don't name the status codes for size or deadline failures, so confirm with responseDetails and the body. | backend-routing-and-timeouts.md |
| CORS preflight fails or latency is high | CORS pass-through or slow backend | backend-routing-and-timeouts.md |
api-configs create fails with an error about the OpenAPI document, such as an unsupported extension or an invalid path, parameter, server, or security requirement | A spec problem | Hand off to api-gateway-openapi-spec-authoring; if it isn't installed, see OpenAPI pre-flight check |
api-configs create fails with a service account, concurrency, or limit error, or gateways create or gateways update fails | Service account, concurrent creates, limits, or the backend deadline | config-deployment-errors.md |
400 "The request was malformed" from an old TLS client, TLS scan findings, custom domain, or no log entry at all | TLS enforcement, DNS, load balancer, or wrong host | networking-domains-tls.md |
| Errors on several gateways, or on an unchanged config, with healthy backends | Possible Google Cloud issue | limits-and-escalation.md |
If the request also needs log queries or backend inspection commands, use triage-and-logs.md.
6. State the root cause
Give the cause, the evidence (redacted, quoted verbatim from logs or command output), and the public doc section that explains it. If the evidence fits more than one cause, list at most three, say what would tell them apart, and collect that evidence before proposing a fix.
7. Propose the fix
Show the exact command, the resource it changes, its effect on live traffic, and how to undo it. Wait for approval, then run it, or hand it to the user if they prefer. Keep these rules in mind:
- To change the OpenAPI document, create a new API config and deploy it with
gcloud api-gateway gateways update. Before you create the config, check quota metrics with theapi-gateway-backend-security-and-rate-limitingskill, because the newest API config's quota metrics apply to every gateway of the API. - Before you create a new API config, check the OpenAPI document with the linter (see OpenAPI pre-flight check).
8. Verify
Read the logs again for new entries after the change, or repeat the failing
request. Repeat a request yourself only if it's safe to repeat, such as a
GET; otherwise ask the user to repeat it, because a repeated POST can
change data in their backend. After gateways update, wait until the
gateway's state is ACTIVE before you test.
9. Escalate when the evidence points to Google Cloud
Escalate to Cloud Customer Care when the
service account is active, the required APIs are enabled, and no log exclusion
or wrong scope explains it, but requests get 500 errors with no gateway log
entry; when several gateways fail at once without a config change; when errors
are intermittent on an unchanged config while the backend logs stay clean;
when control-plane operations keep failing with internal errors; or when
Service Health reports an incident. Draft the case text with the evidence
bundle in limits-and-escalation.md. The
user files the case.
OpenAPI pre-flight check
Run the linter on every OpenAPI file before creating an API config. Run it; don't read its source. If you don't have the file, give the user the command to run:
python3 scripts/lint_openapi_for_gateway.py {spec_path} [{spec_path} ...]
It reads the files only, makes no network calls, and prints JSON findings that
each link to the public doc for the limitation. Exit code 0 means no errors,
1 means at least one ERROR finding, and 2 means a usage, parse, or
dependency error. The linter needs Python 3.8 or later. YAML input needs
PyYAML; ask the user before you install it with
pip install "PyYAML>=6.0,<7.0". JSON input doesn't. Fix the ERROR
findings, and then create the API config. If api-configs create still fails
on the OpenAPI document, hand off to api-gateway-openapi-spec-authoring, or
use the error message if that skill isn't installed. Show WARNING findings
to the user and explain them.
Output format
Report findings in this form:
**Problem:** <one sentence in the user's terms>
**Failed hop:** <gateway or backend, and the evidence for it>
**Evidence:** <redacted log fields or command output, verbatim>
**Root cause:** <one or two sentences> (<public doc link>)
**Fix:** <exact command or spec change; approval needed: yes/no>
**Verify:** <how to confirm the fix>
**Open questions:** <anything you couldn't confirm>
Related skills
| Need | Skill |
|---|---|
| Write or change API key, JWT, backend authentication, or quota configuration | api-gateway-backend-security-and-rate-limiting |
Write, migrate, or fix an OpenAPI spec, including OpenAPI errors from api-configs create | api-gateway-openapi-spec-authoring |
MCP /mcp JSON-RPC errors on an MCP-enabled gateway | api-gateway-mcp-server |
| Deep IAM analysis, such as deny policies or role discovery | iam-helper-for-troubleshooting |
| Build a load balancer, Cloud Armor policy, or custom domain front end | google-cloud-global-frontend-configuration |
| Deploy or reconfigure a Cloud Run backend | cloud-run-basics |
Reference files
- references/attribution.md: usage attribution rules for every command you run.
- references/triage-and-logs.md: hostname formats, log queries, log fields, metrics, and backend inspection commands.
- references/auth-errors.md:
401and403on either hop, API keys, JWTs, and the gateway service account. - references/backend-routing-and-timeouts.md:
404, size limits, backend5xx,504and deadlines, CORS, and streaming. - references/config-deployment-errors.md: API config and gateway create, update, and delete failures other than OpenAPI errors, and quota metric conflicts.
- references/networking-domains-tls.md: custom domains, load balancers, TLS, and requests that never reach the gateway.
- references/limits-and-escalation.md: product limits, quota increases, unsupported features, and the Cloud Customer Care evidence bundle.
- scripts/lint_openapi_for_gateway.py: offline linter for documented OpenAPI limitations.
Files
9- SKILL.md
83d98a963e19.2 KB - references/attribution.md
c1ca116b581.9 KB - references/auth-errors.md
edb16ec81510.2 KB - references/backend-routing-and-timeouts.md
7102ceaec37.4 KB - references/config-deployment-errors.md
a2457d72864.9 KB - references/limits-and-escalation.md
3e7dd8401f4.4 KB - references/networking-domains-tls.md
2ba2b93a314.8 KB - references/triage-and-logs.md
4fd37013d47.6 KB - scripts/lint_openapi_for_gateway.py
81d44b31ec25.0 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from google/skills8
Audits AI agent data access, blast radius, and blocked policy operations in Google Cloud by querying Cloud Audit Logs via BigQuery. Use when investigating what resources or services an agent accessed, identifying top originating principals the agent is acting as, or triaging PERMISSION_DENIED errors
Manages Google Cloud Agent Registry (agentregistry.googleapis.com) resources using gcloud CLI and Kubernetes manifests, including agents, MCP servers, endpoints, services, bindings, AI applications, skills and skill revisions, resource-level IAM policies, Cloud Run and GKE automatic workload registr
Configures best-practice alerting policies for AI agents using OpenTelemetry (OTel) metrics, generating output as Terraform (.tf) configuration files. Use when analyzing, writing, or deploying alerting policies to monitor agent latency, error rates, token usage, and quality metrics. Don't use for st
Designs, engineers, and validates enterprise Gemini platform architectures. Use when designing multi-project hierarchies (Host, Central Governance Hub, Runtime Spoke, Tool/MCP Spoke), configuring Agent Gateway, authoring Agent Connectivity Templates (ALL_TRAFFIC vs PRIVATE_RANGES_ONLY), deploying Se
Customizes an autorater (evaluation metric) for an AI agent so its grades match the user's own judgment, starting from the agent's real trajectories. Use when a user wants a metric tailored to their agent, wants to turn failing trajectories into rubrics, says an existing autorater grades their agent
Deploy open models or custom weights from Model Garden to Agent Platform endpoints, check the status of an in-progress deployment operation, or clean up resources by undeploying models and deleting endpoints. Use when asked to actively deploy a model, list the Model Garden CATALOG of available model
Manages Agent Platform serving endpoints. Use when you need to create, list, describe, update, or delete serving endpoints for model deployment on Agent Platform. Also use when troubleshooting endpoint permission, quota, or resource busy errors. Don't use for deploying models to endpoints or for run
Measures and improves the quality of AI models and agents on Google Cloud using the Eval Quality Flywheel methodology. Use when generating synthetic user scenarios, evaluating an agent or model, building an eval dataset, picking or writing evaluation metrics, analyzing failures, comparing results be
Related backend skillsscan passed
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
cuOpt REST server — start server, endpoints, Python/curl client examples. Use when the user is deploying or calling the REST API.
Report browser/API/CLI/job/worker/webhook bugs. Use for: qa report only, just report bugs, test but dont fix. (gstack)
Builds, upgrades and reviews Nuxt 4 full-stack applications: the app/ directory layout, SSR-safe data fetching with useFetch, useAsyncData and $fetch, Nitro server routes with nuxt/server handlers, runtime config and server-only secrets, hybrid rendering with route rules (SSR, SSG, SWR, ISR), server
Use this skill when the user wants to build tool/scripts or achieve a task where using data from the Hugging Face API would help. This is especially useful when chaining or combining API calls or the task will be repeated/automated. This Skill creates a reusable script to fetch, enrich or process da
Creates an API Gateway stage with CloudWatch logging, X-Ray tracing, throttling, WAF integration, and IAM roles following AWS best practices. Use when deploying a REST API to different environments such as dev, test, or production.