API Gateway Troubleshooting

API Gateway Troubleshooting

Diagnoses failing requests and deployment errors on Google Cloud API Gateway: 4xx/5xx, quotas, CORS, config creation, domains and TLS, working from docs and the user's own project.

Skill files9 files

references/

scripts/

SKILL.md350 lines
1
---
2
name: api-gateway-troubleshooting
3
metadata:
4
version: "1.1.0"
5
category: Serverless
6
description: >-
7
Diagnoses failing requests and deployment errors on Google Cloud API Gateway.
8
Use when calls through a gateway return 4xx or 5xx errors, including 429 and
9
other quota errors, time out, or fail a CORS preflight; when
10
`api-configs create` fails with a service account, concurrency, or limit
11
error, or `gateways create` or `gateways update` fails; when a custom domain,
12
load balancer, or TLS finding involves a gateway; or when the user asks if
13
Google is at fault. Don't use for Apigee, Cloud Endpoints, or GKE Gateway API.
14
For OpenAPI errors from `api-configs create`, use
15
api-gateway-openapi-spec-authoring; for setting up or changing API keys,
16
JWTs, or quotas, use api-gateway-backend-security-and-rate-limiting; for MCP
17
`/mcp` errors, use api-gateway-mcp-server.
18
---
19
20
# API Gateway Troubleshooting
21
22
Use this skill to find out why requests to a deployed Google Cloud API Gateway
23
fail and how to fix them. Work only from three sources of evidence:
24
25
1. Public Google Cloud documentation, linked from this skill.
26
2. The user's own project, read with the user's own credentials.
27
3. Files and output that the user provides, such as an OpenAPI document, an
28
error response, or a pasted log entry.
29
30
## Scope
31
32
This skill covers only Google Cloud API Gateway. If the question is about
33
Apigee, Cloud Endpoints, or GKE Gateway API, reply that this skill covers only
34
Google Cloud API Gateway, and don't run its steps or commands.
35
36
## Usage Attribution
37
38
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
39
MUST read and follow the instructions in
40
[Usage Attribution](references/attribution.md).
41
42
## Ground rules
43
44
| Rule | Why |
45
| :--- | :--- |
46
| 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. |
47
| 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. |
48
| 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. |
49
| 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. |
50
| Redact API keys, bearer tokens, and JWTs before you show log entries, commands, or files. | Request logs and pasted output can contain credentials. |
51
| 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. |
52
| 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. |
53
| For Preview features (streaming, MCP, model routing), check the [release notes](https://docs.cloud.google.com/api-gateway/docs/release-notes.md.txt) before answering. | Preview behavior changes between releases. |
54
55
## Prerequisites
56
57
1. **Google Cloud CLI.** Use a recent `gcloud` (the commands here were
58
checked with version 591.0.0); see
59
[Install the gcloud CLI](https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt).
60
Don't install or update software without the user's approval. If
61
`gcloud` isn't available or the user says not to run commands, work in
62
*evidence mode*: give the user the read-only commands to run, and diagnose
63
from the output, response bodies, and log entries they paste.
64
2. **Authentication.** Use the user's existing `gcloud auth login` session;
65
this skill doesn't need application-default credentials.
66
3. **Project.** Ask which project hosts the gateway and pass
67
`--project={project_id}` on every command. Don't run `gcloud config set`,
68
because it changes the user's environment. This skill troubleshoots
69
existing gateways and never creates projects.
70
4. **Billing.** The project needs an active billing account even when usage
71
stays in the free tier; see
72
[API Gateway pricing](https://cloud.google.com/api-gateway/pricing).
73
5. **APIs.** API Gateway requires `apigateway.googleapis.com`,
74
`servicemanagement.googleapis.com`, and `servicecontrol.googleapis.com`. A
75
gateway can keep responding while one of them is missing, and its logs then
76
stay empty, so check with
77
`gcloud services list --enabled --project={project_id}`. Enabling a missing
78
API is a change that needs approval.
79
6. **IAM roles for diagnosis (read-only):** `roles/apigateway.viewer`,
80
`roles/logging.viewer`, `roles/serviceusage.serviceUsageViewer`, and
81
`roles/iam.serviceAccountViewer` (to check the gateway's service account).
82
For Cloud Run backends, add `roles/run.viewer`; to trace a custom domain
83
through its load balancer, add `roles/compute.viewer`; to check an API key's
84
project, `roles/serviceusage.serviceUsageViewer` is also needed there.
85
7. **IAM roles for fixes (only after approval):** `roles/apigateway.admin`;
86
`roles/iam.serviceAccountUser` on the gateway's service account, because
87
creating or updating an API config or a gateway requires
88
`iam.serviceAccounts.actAs`;
89
`roles/run.admin` to change a Cloud Run service's IAM policy or ingress;
90
`roles/serviceusage.serviceUsageAdmin` to enable an API or a managed
91
service, plus `roles/servicemanagement.serviceConsumer` on the API's
92
managed service to enable it in another project; and
93
`roles/iam.serviceAccountAdmin` to re-enable a disabled service account.
94
8. **Region.** Gateways are regional. Use the region that
95
`gateways list` reports. When a fix needs a new gateway, create it in the
96
original gateway's region, or in `us-central1` if the user has no
97
preference; see
98
[API Gateway deployment model](https://docs.cloud.google.com/api-gateway/docs/deployment-model.md.txt)
99
and [Cloud locations](https://cloud.google.com/about/locations).
100
101
## Workflow
102
103
Copy this checklist into your notes and tick it off as you go:
104
105
```
106
- [ ] 1. Context collected
107
- [ ] 2. Gateway identified by defaultHostname
108
- [ ] 3. Expected or transient states ruled out
109
- [ ] 4. Gateway log entry read (bounded query)
110
- [ ] 5. One branch chosen from the classification table
111
- [ ] 6. Root cause stated with redacted evidence and a doc link
112
- [ ] 7. Fix proposed, approved, and applied (or handed to the user)
113
- [ ] 8. Fix verified
114
- [ ] 9. Escalated, if the evidence points to Google Cloud
115
```
116
117
### 1. Collect context
118
119
Extract these from the conversation first, and ask only for what's missing:
120
121
| Needed | Why |
122
| :--- | :--- |
123
| `{project_id}` of the gateway | Every command is scoped to it. |
124
| Failing URL (host and path) or `{gateway_id}` and `{region}` | Identifies the gateway. |
125
| HTTP method, status code, and response body | Separates gateway errors from backend errors. |
126
| Approximate time of the failure, in UTC | Bounds the log query. |
127
| What changed recently (new API config, IAM, backend deploy, DNS) | Recent changes are the first place to look. |
128
| Authentication used by the caller (API key, JWT, none) | Selects the auth branch. |
129
130
If the project or the host is unknown, stop and ask before you run any
131
`gcloud` command. Don't guess project IDs, and don't use the active `gcloud`
132
project instead.
133
134
### 2. Identify the gateway
135
136
List the project's gateways:
137
138
```bash
139
gcloud api-gateway gateways list --project={project_id} \
140
--format="table(name.basename():label=GATEWAY,name.segment(3):label=REGION,defaultHostname,state,apiConfig)"
141
```
142
143
Match the request host against `defaultHostname`. Don't decide from the URL
144
suffix: a gateway's hostname can use either of two `gateway.dev` formats or,
145
for older streaming and model-routing gateways, a `run.app` format. Don't
146
guess the owning project from numbers in the hostname either; list the
147
gateways in the project the user names. A custom domain points at a load
148
balancer whose serverless NEG targets the gateway. See
149
[references/triage-and-logs.md](references/triage-and-logs.md) for the
150
hostname formats and how to trace a custom domain.
151
152
If no gateway in the project matches, confirm the product before going on
153
(see [Scope](#scope)).
154
155
Then read the gateway's details, including its API config and streaming mode:
156
157
```bash
158
gcloud api-gateway gateways describe {gateway_id} \
159
--location={region} --project={project_id}
160
```
161
162
### 3. Rule out expected and transient states
163
164
- **Gateway `state` isn't `ACTIVE`:** `CREATING` or `UPDATING` means an
165
operation is still running, so wait and check again. `FAILED` means
166
creation failed; read the error of the failed operation. `DELETING` means
167
the gateway is being removed.
168
- **API config just created:** creating a complex API config can take up to
169
ten minutes, and only one config can be created for an API at a time.
170
- **First requests after an idle period:** API Gateway has cold-start
171
latency.
172
- **Google Cloud incident:** check the
173
[Service Health dashboard](https://docs.cloud.google.com/service-health/docs/overview.md.txt).
174
175
### 4. Read the gateway log entry
176
177
Use a bounded query that prints only the fields you need. Replace
178
`{status_code}` with the status the caller saw:
179
180
```bash
181
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}' \
182
--project={project_id} --freshness=1h --limit=20 \
183
--format="json(timestamp,httpRequest.status,httpRequest.latency,httpRequest.requestUrl,jsonPayload.responseDetails,jsonPayload.apiConfig,jsonPayload.apiMethod)"
184
```
185
186
If you know the failure time, replace `--freshness` with a
187
`timestamp>="{start_utc}" AND timestamp<="{end_utc}"` filter that spans about
188
30 minutes around it. Read `httpRequest.status`, `httpRequest.requestUrl`,
189
`jsonPayload.responseDetails`, `jsonPayload.apiConfig`, and
190
`jsonPayload.apiMethod`. Keep the `--format` field list, because a full entry
191
can contain the caller's credentials, and redact credentials before you quote
192
any field, including a `key` query parameter in `httpRequest.requestUrl`.
193
194
To compare API configs, compare only the `apis/{api_id}/configs/{config_id}`
195
part: the same config can appear as a full resource name
196
(`//apigateway.googleapis.com/projects/...`) and with either the project
197
number or the project ID.
198
199
`jsonPayload.responseDetails` decides the branch: `via_upstream` means the
200
backend produced the response; any other value means the gateway produced it.
201
The troubleshooting page explains `via_upstream` and
202
`service_control_quota_error`, and the model routing page explains the
203
`model_router_*` values that model-routing gateways log. Quote any other value
204
as-is, and don't explain how the gateway works internally.
205
206
### 5. Classify and follow one branch
207
208
Pick the first row that matches, and load only the reference file it names.
209
210
| What you see | Likely cause | Reference |
211
| :--- | :--- | :--- |
212
| The request path ends in `/mcp`, or the response is a JSON-RPC error | The MCP setup | Hand off to `api-gateway-mcp-server`; if it isn't installed, read the MCP troubleshooting table in [Configure MCP](https://docs.cloud.google.com/api-gateway/docs/mcp-configure.md.txt) |
213
| `401` or `403` with `via_upstream` | The backend rejected the gateway: invoker role, audience, or deleted service account | [auth-errors.md](references/auth-errors.md) |
214
| 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](references/auth-errors.md) |
215
| `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](references/auth-errors.md) |
216
| `500` with `service_control_quota_error` | Quota metric missing from the newest API config | [config-deployment-errors.md](references/config-deployment-errors.md) |
217
| `429` with `service_control_quota_error` | The caller exceeded the API's quota | [limits-and-escalation.md](references/limits-and-escalation.md) |
218
| `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](references/backend-routing-and-timeouts.md) |
219
| CORS preflight fails or latency is high | CORS pass-through or slow backend | [backend-routing-and-timeouts.md](references/backend-routing-and-timeouts.md) |
220
| `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](#openapi-pre-flight-check) |
221
| `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](references/config-deployment-errors.md) |
222
| `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](references/networking-domains-tls.md) |
223
| Errors on several gateways, or on an unchanged config, with healthy backends | Possible Google Cloud issue | [limits-and-escalation.md](references/limits-and-escalation.md) |
224
225
If the request also needs log queries or backend inspection commands, use
226
[triage-and-logs.md](references/triage-and-logs.md).
227
228
### 6. State the root cause
229
230
Give the cause, the evidence (redacted, quoted verbatim from logs or command
231
output), and the public doc section that explains it. If the evidence fits
232
more than one cause, list at most three, say what would tell them apart, and
233
collect that evidence before proposing a fix.
234
235
### 7. Propose the fix
236
237
Show the exact command, the resource it changes, its effect on live traffic,
238
and how to undo it. Wait for approval, then run it, or hand it to the user if
239
they prefer. Keep these rules in mind:
240
241
- To change the OpenAPI document, create a new API config and deploy it with
242
`gcloud api-gateway gateways update`. The newest API config's quota metrics
243
apply to every gateway of the API. Before you run `api-configs create`,
244
load the `api-gateway-backend-security-and-rate-limiting` skill and run its
245
`scripts/check_quota_metrics.py`. It compares the new spec's quota metrics
246
with the API configs that gateways serve. If that skill isn't installed,
247
keep every quota metric and its limit that a running API config uses.
248
- Before you create a new API config, check the OpenAPI document with the
249
linter (see [OpenAPI pre-flight check](#openapi-pre-flight-check)).
250
251
### 8. Verify
252
253
Read the logs again for new entries after the change, or repeat the failing
254
request. Repeat a request yourself only if it's safe to repeat, such as a
255
`GET`; otherwise ask the user to repeat it, because a repeated `POST` can
256
change data in their backend. After `gateways update`, wait until the
257
gateway's `state` is `ACTIVE` before you test.
258
259
### 9. Escalate when the evidence points to Google Cloud
260
261
Escalate to [Cloud Customer Care](https://cloud.google.com/support) when the
262
service account is active, the required APIs are enabled, and no log exclusion
263
or wrong scope explains it, but requests get `500` errors with no gateway log
264
entry; when several gateways fail at once without a config change; when errors
265
are intermittent on an unchanged config while the backend logs stay clean;
266
when control-plane operations keep failing with internal errors; or when
267
Service Health reports an incident. Draft the case text with the evidence
268
bundle in [limits-and-escalation.md](references/limits-and-escalation.md). The
269
user files the case.
270
271
## OpenAPI pre-flight check
272
273
Run the linter on every OpenAPI file before creating an API config. Run it;
274
don't read its source. If you don't have the file, give the user the command
275
to run:
276
277
```bash
278
python3 scripts/lint_openapi_for_gateway.py {spec_path} [{spec_path} ...]
279
```
280
281
It reads the files only, makes no network calls, and prints JSON findings that
282
each link to the public doc for the limitation. Exit code `0` means no errors,
283
`1` means at least one `ERROR` finding, and `2` means a usage, parse, or
284
dependency error. The linter needs Python 3.8 or later. YAML input needs
285
PyYAML; ask the user before you install it with
286
`pip install "PyYAML>=6.0,<7.0"`. JSON input doesn't. Fix the `ERROR`
287
findings, and then create the API config. If `api-configs create` still fails
288
on the OpenAPI document, hand off to `api-gateway-openapi-spec-authoring`, or
289
use the error message if that skill isn't installed. Show `WARNING` findings
290
to the user and explain them.
291
292
## Output format
293
294
Report findings in this form:
295
296
```
297
**Problem:** <one sentence in the user's terms>
298
**Failed hop:** <gateway or backend, and the evidence for it>
299
**Evidence:** <redacted log fields or command output, verbatim>
300
**Root cause:** <one or two sentences> (<public doc link>)
301
**Fix:** <exact command or spec change; approval needed: yes/no>
302
**Verify:** <how to confirm the fix>
303
**Open questions:** <anything you couldn't confirm>
304
```
305
306
## Related skills
307
308
| Need | Skill |
309
| :--- | :--- |
310
| Write or change API key, JWT, backend authentication, or quota configuration | `api-gateway-backend-security-and-rate-limiting` |
311
| Write, migrate, or fix an OpenAPI spec, including OpenAPI errors from `api-configs create` | `api-gateway-openapi-spec-authoring` |
312
| MCP `/mcp` JSON-RPC errors on an MCP-enabled gateway | `api-gateway-mcp-server` |
313
| Deep IAM analysis, such as deny policies or role discovery | `iam-helper-for-troubleshooting` |
314
| Build a load balancer, Cloud Armor policy, or custom domain front end | `google-cloud-global-frontend-configuration` |
315
| Deploy or reconfigure a Cloud Run backend | `cloud-run-basics` |
316
317
If an API Gateway skill in this table isn't installed, give the user this
318
command to install the four API Gateway skills. Until it is installed, use the
319
fallback in this skill.
320
321
```bash
322
npx skills add google/skills --skill api-gateway-mcp-server --skill api-gateway-backend-security-and-rate-limiting --skill api-gateway-openapi-spec-authoring --skill api-gateway-troubleshooting
323
```
324
325
For another skill in this table, give the user the same command with
326
`--skill {skill_name}`.
327
328
## Reference files
329
330
- [references/attribution.md](references/attribution.md): usage attribution
331
rules for every command you run.
332
- [references/triage-and-logs.md](references/triage-and-logs.md): hostname
333
formats, log queries, log fields, metrics, and backend inspection
334
commands.
335
- [references/auth-errors.md](references/auth-errors.md): `401` and `403` on
336
either hop, API keys, JWTs, and the gateway service account.
337
- [references/backend-routing-and-timeouts.md](references/backend-routing-and-timeouts.md):
338
`404`, size limits, backend `5xx`, `504` and deadlines, CORS, and streaming.
339
- [references/config-deployment-errors.md](references/config-deployment-errors.md):
340
API config and gateway create, update, and delete failures other than
341
OpenAPI errors, and quota metric conflicts.
342
- [references/networking-domains-tls.md](references/networking-domains-tls.md):
343
custom domains, load balancers, TLS, and requests that never reach the
344
gateway.
345
- [references/limits-and-escalation.md](references/limits-and-escalation.md):
346
product limits, quota increases, unsupported features, and the Cloud
347
Customer Care evidence bundle.
348
- [scripts/lint_openapi_for_gateway.py](scripts/lint_openapi_for_gateway.py):
349
offline linter for documented OpenAPI limitations.
350

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…