Prerequisites
Installation
Install the Switchport SDK using go get:
go get github.com/switchport-ai/switchport-go
Or add it to your go.mod:
require github.com/switchport-ai/switchport-go v0.1.0
Then run:
Get Your API Key
Navigate to Settings
Go to Settings → API Keys in the dashboard.
Copy your API key
Copy your API key (it starts with sp_).
Set Your API Key
Set your API key as an environment variable:
export SWITCHPORT_API_KEY=sp_your_key_here
Create Your First Prompt
Before using the SDK, you need to create a prompt in the Switchport dashboard:
Create a prompt config
- Go to Prompts → New Prompt Config
- Name: “Welcome Message”
- Key:
welcome-message
- Click Create
Add a version
- Click Add Version
- Model: Select
gpt-5 (or another model)
- Prompt:
Write a friendly welcome message for {{name}}.
- Click Save
Publish the version
Click Publish on the version you just created.
The SDK calls LLMs on your behalf, so you need to configure your LLM API keys:
Go to Organization Settings
Navigate to Settings → Organization Settings
Add your LLM API keys
Add API keys for the LLM providers you want to use:
- OpenAI API key (for GPT models)
- Anthropic API key (for Claude models)
- Google API key (for Gemini models)
Save
Click Save to store your API keys securely.
Execute Your First Prompt
Create a file main.go:
package main
import (
"fmt"
"log"
"github.com/switchport-ai/switchport-go/switchport"
)
func main() {
// Initialize client (reads API key from environment)
client, err := switchport.NewClient("")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Execute a prompt
response, err := client.Prompts.Execute(
"welcome-message",
nil, // no subject
map[string]interface{}{"name": "Alice"},
)
if err != nil {
log.Fatalf("Failed to execute prompt: %v", err)
}
fmt.Println("Generated text:")
fmt.Println(response.Text)
fmt.Printf("\nModel: %s\n", response.Model)
fmt.Printf("Version: %s\n", response.VersionName)
}
Run it:
You should see output like:
Generated text:
Hello Alice! Welcome to our platform. We're excited to have you here!
Model: gpt-5
Version: v1
Record Your First Metric
Now let’s track a metric. First, create a metric definition in the dashboard:
Create metric definition
- Go to Metrics → New Metric
- Key:
satisfaction
- Name: “User Satisfaction”
- Type:
float
- Click Create
Then record a metric in your code:
package main
import (
"fmt"
"log"
"github.com/switchport-ai/switchport-go/switchport"
)
func main() {
client, err := switchport.NewClient("")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Execute prompt with subject identification
subject := map[string]interface{}{"user_id": "user_123"}
response, err := client.Prompts.Execute(
"welcome-message", subject,
map[string]interface{}{"name": "Alice"},
)
if err != nil {
log.Fatalf("Failed to execute prompt: %v", err)
}
fmt.Println(response.Text)
// Simulate user feedback (1-5 stars)
userRating := 4.5
// Record metric with same subject
result, err := client.Metrics.Record(
"satisfaction",
userRating,
subject, // Same subject!
nil, // timestamp (nil = current time)
)
if err != nil {
log.Fatalf("Failed to record metric: %v", err)
}
fmt.Printf("\nMetric recorded! Event ID: %s\n", result.MetricEventID)
}
Always use the same subject when executing prompts and recording metrics. This ensures metrics are correctly aggregated per prompt version.
Next Steps
A/B Testing
Learn how to run A/B tests with multiple prompt versions
API Reference
Explore the full API reference
Examples
See more code examples
Core Concepts
Understand key concepts