Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions src/content/docs/docs/deployment/any-platform.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -463,80 +463,80 @@ You can deploy Genkit flows as web services using any platform that can host a D

1. Create a directory for the Genkit sample project:

```bash
mkdir -p ~/tmp/genkit-any-project
cd ~/tmp/genkit-any-project
```
```bash
mkdir -p ~/tmp/genkit-any-project
cd ~/tmp/genkit-any-project
```

2. Initialize a Dart project:

```bash
dart create -t console-simple .
```
```bash
dart create -t console-simple .
```

3. Add Genkit dependencies:

```bash
dart pub add genkit genkit_shelf shelf shelf_router genkit_google_genai
```
```bash
dart pub add genkit genkit_shelf shelf shelf_router genkit_google_genai
```

4. Create a sample app using Genkit and Shelf:

```dart title="bin/server.dart"
import 'dart:io';
import 'package:genkit/genkit.dart';
import 'package:genkit_shelf/genkit_shelf.dart';
import 'package:genkit_google_genai/genkit_google_genai.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_router/shelf_router.dart';
import 'package:schemantic/schemantic.dart';

void main() async {
final ai = Genkit(
plugins: [googleAI(apiKey: Platform.environment['GOOGLE_API_KEY'])],
model: googleAI.gemini('gemini-2.5-flash'),
);

final flow = ai.defineFlow(
name: 'flow',
fn: (String input, _) async => 'Processed $input',
inputSchema: .string(),
outputSchema: .string(),
);

final router = Router();
// Mount the flow handler
router.post('/flow', shelfHandler(flow));

// Create a handler pipeline (e.g., adding logging)
final handler = const Pipeline()
.addMiddleware(logRequests())
.addHandler(router.call);

// Start the server
final port = int.parse(Platform.environment['PORT'] ?? '8080');
final server = await io.serve(handler, InternetAddress.anyIPv4, port);
print('Server running on port ${server.port}');
}
```
```dart title="bin/server.dart"
import 'dart:io';
import 'package:genkit/genkit.dart';
import 'package:genkit_shelf/genkit_shelf.dart';
import 'package:genkit_google_genai/genkit_google_genai.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_router/shelf_router.dart';
import 'package:schemantic/schemantic.dart';

void main() async {
final ai = Genkit(
plugins: [googleAI(apiKey: Platform.environment['GOOGLE_API_KEY'])],
model: googleAI.gemini('gemini-2.5-flash'),
);

final flow = ai.defineFlow(
name: 'flow',
fn: (String input, _) async => 'Processed $input',
inputSchema: .string(),
outputSchema: .string(),
);

final router = Router();
// Mount the flow handler
router.post('/flow', shelfHandler(flow));

// Create a handler pipeline (e.g., adding logging)
final handler = const Pipeline()
.addMiddleware(logRequests())
.addHandler(router.call);

// Start the server
final port = int.parse(Platform.environment['PORT'] ?? '8080');
final server = await io.serve(handler, InternetAddress.anyIPv4, port);
print('Server running on port ${server.port}');
}
```

5. **Compile for Deployment**:

Dart applications can be compiled into self-contained executables (AOT compilation), which makes them easy to deploy without needing the full Dart SDK on the target server.

```bash
dart compile exe bin/server.dart -o server
```
```bash
dart compile exe bin/server.dart -o server
```

The resulting `server` file is a standalone executable (on the same architecture).

6. **Deploy**:

Upload the `server` executable to your hosting provider and configure it to run. Ensure you set the necessary environment variables:
Upload the `server` executable to your hosting provider and configure it to run. Ensure you set the necessary environment variables:

- `PORT`: The port your server should listen on (defaults to 8080 in the code above).
- `GOOGLE_API_KEY`: Your Google GenAI API key.
- `PORT`: The port your server should listen on (defaults to 8080 in the code above).
- `GOOGLE_API_KEY`: Your Google GenAI API key.

</Lang>

Expand Down
30 changes: 15 additions & 15 deletions src/content/docs/docs/deployment/cloud-run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ You can easy deploy your Genkit Dart flows to Cloud Run as a containerized servi
2. Link the project to a billing account.
3. Configure the Google Cloud CLI:

```bash
gcloud init
```
```bash
gcloud init
```

## 2. Prepare your Dart project

Expand Down Expand Up @@ -531,21 +531,21 @@ Most flows require API keys (like `GOOGLE_API_KEY` for Gemini). You should use [

1. Create a secret for your API key:

```bash
gcloud secrets create google-api-key --data-file=-
# (Press Enter, paste your API key, then press Ctrl+D)
```
```bash
gcloud secrets create google-api-key --data-file=-
# (Press Enter, paste your API key, then press Ctrl+D)
```

2. Deploy the service, referencing the secret:

```bash
gcloud run deploy genkit-server \
--source . \
--port 3400 \
--allow-unauthenticated \
--region us-central1 \
--set-secrets GOOGLE_API_KEY=google-api-key:latest
```
```bash
gcloud run deploy genkit-server \
--source . \
--port 3400 \
--allow-unauthenticated \
--region us-central1 \
--set-secrets GOOGLE_API_KEY=google-api-key:latest
```

_Note: Replace `3400` with your default port if different, but Cloud Run defaults to passing 8080 as `PORT` env var, which your code should respect._

Expand Down
26 changes: 13 additions & 13 deletions src/content/docs/docs/frameworks/shelf.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,18 @@ Since a Genkit Shelf application is just a standard Dart HTTP server, you can de

1. **Create a Dockerfile**:

```dockerfile
FROM dart:stable AS build
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get
COPY . .
RUN dart compile exe bin/server.dart -o bin/server

FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/bin/server /app/bin/
CMD ["/app/bin/server"]
```
```dockerfile
FROM dart:stable AS build
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get
COPY . .
RUN dart compile exe bin/server.dart -o bin/server

FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/bin/server /app/bin/
CMD ["/app/bin/server"]
```

2. **Build and Deploy** (e.g., using Cloud Build and Cloud Run).
26 changes: 13 additions & 13 deletions src/content/docs/docs/integrations/google-genai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1112,19 +1112,19 @@ void main() {

Requires a Gemini API Key, which you can get from [Google AI Studio](https://aistudio.google.com/apikey).

1. **Environment variables**: Set `GEMINI_API_KEY`
2. **Plugin configuration**: Pass `apiKey` when initializing the plugin (shown above)
3. **Per-request**: Override the API key for specific requests in the config:

```dart
final response = await ai.generate(
model: googleAI.gemini('gemini-2.5-flash'),
prompt: 'Your prompt here',
config: GeminiOptions(
apiKey: 'different-api-key', // Use a different API key for this request
),
);
```
1. **Environment variables**: Set `GEMINI_API_KEY`
2. **Plugin configuration**: Pass `apiKey` when initializing the plugin (shown above)
3. **Per-request**: Override the API key for specific requests in the config:

```dart
final response = await ai.generate(
model: googleAI.gemini('gemini-2.5-flash'),
prompt: 'Your prompt here',
config: GeminiOptions(
apiKey: 'different-api-key', // Use a different API key for this request
),
);
```

## Language Models

Expand Down
28 changes: 14 additions & 14 deletions src/content/docs/docs/integrations/vertex-ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,33 @@ The plugin requires you to specify your Google Cloud project ID, the [region](ht

You can also pass this value directly:

```dart
vertexAI(projectId: 'my-project-id')
```
```dart
vertexAI(projectId: 'my-project-id')
```

- By default, `vertexAI` gets the Vertex AI API location from the `GCLOUD_LOCATION` environment variable.

You can also pass this value directly:

```dart
vertexAI(location: 'us-central1')
```
```dart
vertexAI(location: 'us-central1')
```

- To provide API credentials, you need to set up Google Cloud Application Default Credentials.

1. To specify your credentials:
1. To specify your credentials:

- If you're running your flow from a Google Cloud environment (Cloud Functions, Cloud Run, and so on), this is set automatically.
- If you're running your flow from a Google Cloud environment (Cloud Functions, Cloud Run, and so on), this is set automatically.

- On your local dev environment, do this by running:
- On your local dev environment, do this by running:

```shell
gcloud auth application-default login
```
```shell
gcloud auth application-default login
```

- For other environments, see the [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) docs.
- For other environments, see the [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) docs.

2. In addition, make sure the account is granted the Vertex AI User IAM role (`roles/aiplatform.user`). See the Vertex AI [access control](https://cloud.google.com/vertex-ai/generative-ai/docs/access-control) docs.
2. In addition, make sure the account is granted the Vertex AI User IAM role (`roles/aiplatform.user`). See the Vertex AI [access control](https://cloud.google.com/vertex-ai/generative-ai/docs/access-control) docs.

## Usage

Expand Down
12 changes: 6 additions & 6 deletions src/content/docs/docs/local-observability.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ Logs are automatically correlated with the current trace context when using `Zon

To view traces locally:

1. Start the Genkit Developer UI:
1. Start the Genkit Developer UI:

```bash
genkit start -- dart run
```
```bash
genkit start -- dart run
```

2. Run your flow or action.
3. Open the Developer UI (typically at `http://localhost:4000`) to view traces and metrics.
2. Run your flow or action.
3. Open the Developer UI (typically at `http://localhost:4000`) to view traces and metrics.

</Lang>

Expand Down