Skip to main content

Text Generation

This guide walks you through generating text content using the neuroflash API — from selecting a model to streaming responses and applying a brand voice.

What you'll build

By the end of this guide, you will:

  • Authenticate with the neuroflash API
  • Fetch your workspace
  • List available AI models
  • Send a chat completion request
  • Stream a response in real-time
  • Use multi-turn messages for context
  • Apply a brand voice for consistent tone

Prerequisites

  • A neuroflash account with API access
  • Your client_id and client_secret (see Authentication)

Step 1: Authenticate

curl -X POST https://id.neuroflash.com/oauth/v2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "scope=openid"

Step 2: Get Your Workspace

Fetch your available workspaces and select the first one. The workspace ID is required for most API calls:

curl "https://app.neuroflash.com/api/workspace-service/v1/workspaces" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Step 3: List Available Models

See which AI models are available for your pricing plan:

curl "https://app.neuroflash.com/api/ds-prototypes/model_selection/models" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID"

Response:

[
{
"id": "gpt-4.1-mini",
"name": "GPT-4.1 Mini",
"provider": "openai",
"description": "Fast and cost-effective model for most tasks",
"context_window": 128000,
"available": true,
"reasoning_model": false
},
{
"id": "claude-sonnet-4",
"name": "Claude Sonnet 4",
"provider": "anthropic",
"description": "Excellent for nuanced writing and analysis",
"context_window": 200000,
"available": true,
"reasoning_model": false
},
{
"id": "gpt-5",
"name": "GPT-5",
"provider": "openai",
"description": "Most capable OpenAI model with reasoning",
"context_window": 128000,
"available": true,
"reasoning_model": true
}
]

Model availability by plan:

PlanModels
Freegpt-4.1-mini, mistral-7b-instruct, mistral-medium-3.1, claude-sonnet-4, gemini-2.5-flash
ProAll Free models + gpt-5, gpt-4.1, gemini-2.5-pro
BusinessAll Pro models + claude-opus-4.1

Step 4: Send a Chat Completion

Send a message and get a response using the content generation endpoint:

curl -X POST "https://app.neuroflash.com/api/ds-prototypes/content_generation/chat/completions" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4.1-mini",
"messages": [
{
"role": "user",
"content": "Write an outline for a blog post about how small businesses can adopt sustainable technology practices."
}
],
"temperature": 0.7
}'

Response:

{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "gpt-4.1-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "# Blog Post Outline: Sustainable Tech for Small Businesses\n\n## 1. Introduction\n- The growing importance of sustainability...\n\n## 2. Start with Energy Efficiency\n..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 245,
"total_tokens": 273,
"words_used": 364
}
}

Step 5: Stream a Response

For longer responses, use streaming to receive chunks in real-time via Server-Sent Events (SSE):

curl -X POST "https://app.neuroflash.com/api/ds-prototypes/content_generation/chat/completions" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4.1-mini",
"messages": [
{
"role": "user",
"content": "Write a short paragraph about renewable energy benefits."
}
],
"stream": true
}'

SSE Stream Format:

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"In"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" today's"},"finish_reason":null}]}

...

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":15,"completion_tokens":150,"total_tokens":165}}

data: [DONE]

Step 6: Multi-turn Messages

Include previous messages for context in follow-up requests. Pass the full message history in each request:

curl -X POST "https://app.neuroflash.com/api/ds-prototypes/content_generation/chat/completions" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4.1-mini",
"messages": [
{"role": "user", "content": "Write an outline for a blog post about sustainable technology."},
{"role": "assistant", "content": "# Sustainable Technology Blog Post\n\n1. Introduction..."},
{"role": "user", "content": "Make it more conversational and add a real-world example."}
]
}'

Step 7: Apply a Brand Voice

Fetch a brand voice from your workspace and use its description as a system message for consistent tone:

# List brand voices
curl "https://app.neuroflash.com/api/brand-voice-service/v1/workspaces/{workspace_id}/brand-voices?page=1&size=10" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID"

# Use the brand voice description as a system message
curl -X POST "https://app.neuroflash.com/api/ds-prototypes/content_generation/chat/completions" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4.1-mini",
"messages": [
{"role": "system", "content": "Follow this brand voice: YOUR_BRAND_VOICE_DESCRIPTION"},
{"role": "user", "content": "Write a product announcement for our new eco-friendly packaging."}
]
}'

Next Steps