create-zuplo-api 7.8.7 → 7.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -116
- package/dist/index.js +9 -9
- package/dist/shared/env.example +12 -0
- package/dist/templates/ai-gateway/README-template.md +85 -22
- package/dist/templates/ai-gateway/modules/zuplo.runtime.ts +42 -0
- package/dist/templates/default-empty/README-template.md +4 -1
- package/dist/templates/shared/env.example +12 -0
- package/dist/templates/shared/vscode/launch.json +30 -0
- package/dist/templates/shared/vscode/settings.json +20 -0
- package/package.json +1 -1
- package/dist/templates/ai-gateway/env.example +0 -6
- package/dist/templates/ai-gateway/gitignore +0 -8
- package/dist/templates/default/env.example +0 -2
- package/dist/templates/default-empty/env.example +0 -2
- /package/dist/{templates/default-empty → shared}/gitignore +0 -0
- /package/dist/{templates/default → shared}/vscode/launch.json +0 -0
- /package/dist/{templates/default → shared}/vscode/settings.json +0 -0
- /package/dist/templates/{default → shared}/gitignore +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Environment variables for local development.
|
|
2
|
+
#
|
|
3
|
+
# Copy this file to .env and replace the sample values. `zuplo dev` loads .env
|
|
4
|
+
# automatically. .env is gitignored, so real secrets stay out of source control.
|
|
5
|
+
#
|
|
6
|
+
# Reference a variable from config files as $env(EXAMPLE_API_KEY), or from code
|
|
7
|
+
# as `environment.EXAMPLE_API_KEY` (import `environment` from "@zuplo/runtime").
|
|
8
|
+
#
|
|
9
|
+
# For deployed environments, set variables in the Zuplo Portal under
|
|
10
|
+
# Settings > Environment Variables. Docs:
|
|
11
|
+
# https://zuplo.com/docs/articles/environment-variables
|
|
12
|
+
EXAMPLE_API_KEY=replace-me
|
|
@@ -1,22 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
## Zuplo AI Gateway
|
|
2
|
+
|
|
3
|
+
This is a Zuplo AI Gateway that was created with
|
|
4
|
+
[`create-zuplo-api`](https://zuplo.com/docs). It gives your applications one
|
|
5
|
+
OpenAI-compatible API in front of many AI providers, with per-app keys, model
|
|
6
|
+
controls, budgets, caching, and guardrails.
|
|
7
|
+
|
|
8
|
+
## Getting Started
|
|
9
|
+
|
|
10
|
+
The gateway loads each app's configuration (providers, models, and policies)
|
|
11
|
+
from your Zuplo account at request time, so the project must be linked to a
|
|
12
|
+
Zuplo project before it can serve requests.
|
|
13
|
+
|
|
14
|
+
1. Link the project. This writes your project's settings to `.env.zuplo`, which
|
|
15
|
+
is gitignored:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx zuplo link
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. In the [Zuplo Portal](https://portal.zuplo.com), add a provider and create an
|
|
22
|
+
app. Each app gets its own API URL and API key. See
|
|
23
|
+
[Apps](https://zuplo.com/docs/ai-gateway/apps).
|
|
24
|
+
|
|
25
|
+
3. Start the development server:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm run dev
|
|
29
|
+
# or
|
|
30
|
+
yarn dev
|
|
31
|
+
# or
|
|
32
|
+
pnpm dev
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
4. Send a request to the local gateway. Replace `<app_id>` with the ID from your
|
|
36
|
+
app's API URL and set `ZUPLO_APP_API_KEY` to the app's API key:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
curl http://localhost:9000/<app_id>/v1/chat/completions \
|
|
40
|
+
-H "Authorization: Bearer $ZUPLO_APP_API_KEY" \
|
|
41
|
+
-H "Content-Type: application/json" \
|
|
42
|
+
-d '{
|
|
43
|
+
"model": "openai/gpt-4o-mini",
|
|
44
|
+
"messages": [{ "role": "user", "content": "Say hi" }]
|
|
45
|
+
}'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Endpoints
|
|
49
|
+
|
|
50
|
+
Every request is scoped to an app by the first path segment, `/{app_id}`. For
|
|
51
|
+
the supported endpoints and which providers serve each one, see the
|
|
52
|
+
[AI Gateway documentation](https://zuplo.com/docs/ai-gateway/overview).
|
|
53
|
+
|
|
54
|
+
## Project Structure
|
|
55
|
+
|
|
56
|
+
| Path | What it does |
|
|
57
|
+
| -------------------------- | ---------------------------------------------------------------------- |
|
|
58
|
+
| `config/ai.oas.json` | The catch-all route that sends `/{app_id}/*` to the AI Gateway handler |
|
|
59
|
+
| `config/policies.json` | The policies an app can select for its policy chain |
|
|
60
|
+
| `modules/zuplo.runtime.ts` | Runtime plugins, such as tracing and logging |
|
|
61
|
+
| `.env.example` | Sample environment variables. Copy it to `.env` for local development |
|
|
62
|
+
|
|
63
|
+
An app runs only the policies listed in its policy chain, and it can select only
|
|
64
|
+
policies declared in `config/policies.json`. To add your own policy, write it in
|
|
65
|
+
`modules/` and declare it in `config/policies.json`.
|
|
66
|
+
|
|
67
|
+
## Debugging
|
|
68
|
+
|
|
69
|
+
In VS Code, open **Run and Debug**, select **Launch & Attach Zuplo**, and click
|
|
70
|
+
the green play button.
|
|
71
|
+
|
|
72
|
+
For other editors and more details, see the
|
|
73
|
+
[debugging guide](https://zuplo.com/docs/articles/local-development-debugging).
|
|
74
|
+
|
|
75
|
+
## Deploying
|
|
76
|
+
|
|
77
|
+
Connect the project to source control in the Zuplo Portal. Pushes to your
|
|
78
|
+
default branch deploy the gateway to production.
|
|
79
|
+
|
|
80
|
+
## Learn More
|
|
81
|
+
|
|
82
|
+
To learn more about the AI Gateway, visit the
|
|
83
|
+
[AI Gateway documentation](https://zuplo.com/docs/ai-gateway/overview).
|
|
84
|
+
|
|
85
|
+
To connect with the community join [Discord](https://discord.zuplo.com).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RuntimeExtensions } from "@zuplo/runtime";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `runtimeInit` runs once when your gateway boots. Use it to register plugins
|
|
5
|
+
* and lifecycle hooks. Docs:
|
|
6
|
+
* https://zuplo.com/docs/programmable-api/runtime-extensions
|
|
7
|
+
*/
|
|
8
|
+
export function runtimeInit(runtime: RuntimeExtensions) {
|
|
9
|
+
// `runtime` is unused until you enable a plugin below. This reference keeps
|
|
10
|
+
// linters from flagging it; delete it once you call `runtime.addPlugin`.
|
|
11
|
+
void runtime;
|
|
12
|
+
|
|
13
|
+
// --- OpenTelemetry tracing (optional) ------------------------------------
|
|
14
|
+
// Send traces to Zuplo's built-in tracing. This can also be configured to
|
|
15
|
+
// send traces to a third-party service such as Honeycomb, Grafana, and
|
|
16
|
+
// others. Docs: https://zuplo.com/docs/articles/opentelemetry
|
|
17
|
+
//
|
|
18
|
+
// To enable, run `npm install @zuplo/otel`, then import `OpenTelemetryPlugin`
|
|
19
|
+
// from "@zuplo/otel" and `environment` from "@zuplo/runtime":
|
|
20
|
+
// const isWorkingCopy =
|
|
21
|
+
// environment.ZUPLO_ENVIRONMENT_STAGE === "working-copy";
|
|
22
|
+
// runtime.addPlugin(
|
|
23
|
+
// new OpenTelemetryPlugin({
|
|
24
|
+
// sampling: {
|
|
25
|
+
// headSampler: { ratio: isWorkingCopy ? 1 : 0.1 },
|
|
26
|
+
// },
|
|
27
|
+
// }),
|
|
28
|
+
// );
|
|
29
|
+
// --- Logging (optional) --------------------------------------------------
|
|
30
|
+
// Ship request logs to Datadog. Other log integrations (New Relic, Splunk,
|
|
31
|
+
// Loki, Dynatrace, and others) follow the same pattern — see the logging
|
|
32
|
+
// overview at https://zuplo.com/docs/articles/logging.
|
|
33
|
+
// Docs: https://zuplo.com/docs/articles/log-plugin-datadog
|
|
34
|
+
//
|
|
35
|
+
// To enable, import the plugin and `environment` from "@zuplo/runtime":
|
|
36
|
+
// runtime.addPlugin(
|
|
37
|
+
// new DataDogLoggingPlugin({
|
|
38
|
+
// apiKey: environment.DATADOG_API_KEY,
|
|
39
|
+
// source: "my-ai-gateway",
|
|
40
|
+
// }),
|
|
41
|
+
// );
|
|
42
|
+
}
|
|
@@ -23,7 +23,10 @@ server will automatically reload the API with your changes.
|
|
|
23
23
|
|
|
24
24
|
## Debugging
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
In VS Code, open **Run and Debug**, select **Launch & Attach Zuplo**, and click
|
|
27
|
+
the green play button.
|
|
28
|
+
|
|
29
|
+
For other editors and more details, see the
|
|
27
30
|
[debugging guide](https://zuplo.com/docs/articles/local-development-debugging).
|
|
28
31
|
|
|
29
32
|
## Learn More
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Environment variables for local development.
|
|
2
|
+
#
|
|
3
|
+
# Copy this file to .env and replace the sample values. `zuplo dev` loads .env
|
|
4
|
+
# automatically. .env is gitignored, so real secrets stay out of source control.
|
|
5
|
+
#
|
|
6
|
+
# Reference a variable from config files as $env(EXAMPLE_API_KEY), or from code
|
|
7
|
+
# as `environment.EXAMPLE_API_KEY` (import `environment` from "@zuplo/runtime").
|
|
8
|
+
#
|
|
9
|
+
# For deployed environments, set variables in the Zuplo Portal under
|
|
10
|
+
# Settings > Environment Variables. Docs:
|
|
11
|
+
# https://zuplo.com/docs/articles/environment-variables
|
|
12
|
+
EXAMPLE_API_KEY=replace-me
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "node",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"name": "Launch Zuplo",
|
|
11
|
+
"runtimeExecutable": "npx",
|
|
12
|
+
"runtimeArgs": ["zuplo", "dev", "--debug-port", "9229", "--port", "9000"],
|
|
13
|
+
"console": "integratedTerminal",
|
|
14
|
+
"internalConsoleOptions": "neverOpen"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "Zuplo Gateway",
|
|
18
|
+
"type": "node",
|
|
19
|
+
"request": "attach",
|
|
20
|
+
"restart": true,
|
|
21
|
+
"port": 9229
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"compounds": [
|
|
25
|
+
{
|
|
26
|
+
"name": "Launch & Attach Zuplo",
|
|
27
|
+
"configurations": ["Launch Zuplo", "Zuplo Gateway"]
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"json.schemas": [
|
|
3
|
+
{
|
|
4
|
+
"fileMatch": ["config/*.oas.json"],
|
|
5
|
+
"url": "https://cdn.zuplo.com/schemas/openapi-v3.1-zuplo.json"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"fileMatch": ["config/policies.json"],
|
|
9
|
+
"url": "https://cdn.zuplo.com/schemas/policies.json"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"fileMatch": ["config/dev-portal.json"],
|
|
13
|
+
"url": "https://cdn.zuplo.com/schemas/dev-portal.json"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"fileMatch": ["docs/sidebar.json"],
|
|
17
|
+
"url": "https://cdn.zuplo.com/schemas/sidebar.json"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# Optional credentials for the pre-declared AI Gateway policies in
|
|
2
|
-
# config/policies.json. Only required when an application's policy chain
|
|
3
|
-
# selects the matching policy. Configure these as environment variables on
|
|
4
|
-
# your Zuplo project (Settings -> Environment Variables) for deployed
|
|
5
|
-
# environments.
|
|
6
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|