Wolfram Language Hints API Reference
Find Wolfram Language code samples relevant to a given query or task
The Wolfram Language Hints API searches Wolfram Language reference materials for code samples relevant to a given input. The response is formatted as text appropriate for use as part of an LLM prompt.
Request API AccessUsing the API
Basic Usage
A basic request to the API takes the following form:
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageHints \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "context": "Draw a pentagram" }'
which yields the following response:
{
"result":"IMPORTANT: Here are some Wolfram documentation snippets that you should use to respond.
======
<result url='https://reference.wolfram.com/language/ref/GraphData#1002612349'>
# GraphData > Examples > Scope > Detailed
Properties > Annotatable Properties Related to Graph Output > 18
Return the name of the ordinary line graph of the pentagram configuration:
```wl
In[1]:= GraphData["PentagramConfigurationGraph", "OrdinaryLineGraph", "Name"]
Out[1]= "PetersenGraph"
```
Return the ordinary line graph of the pentagram configuration:
```wl
In[2]:= GraphData["PentagramConfigurationGraph", "OrdinaryLineGraph", "Graph"]
Out[2]= Image[...]
```
Compute by finding the extraordinary lines of the pentagram configuration:
```wl
In[3]:= config = GraphData["PentagramConfigurationGraph", "Graph", "Labeled"]
Out[3]= Image[...]
In[4]:=
v = GraphEmbedding[config];
configurationlines = ResourceFunction["FindExtraordinaryLines"][v]
Out[4]= {}
```
Complement with all possible pairs of points to get the ordinary lines:
```wl
In[5]:= ordinarylines = Complement[Subsets[VertexList[config],
{2}], Flatten[Subsets[#, {2}]& /@ configurationlines, 1]]
Out[5]= {{1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {1, 9}, {1, 10}, {2, 3}, {2, 4},
{2, 5}, {2, 6}, {2, 7}, {2, 8}, {2, 9}, {2, 10}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8}, {3,
9}, {3, 10}, {4, 5}, {4, 6}, {4, 7}, {4, 8}, {4, 9}, {4, 10}, {5, 6}, {5, 7}, {5, 8}, {5, 9},
{5, 10}, {6, 7}, {6, 8}, {6, 9}, {6, 10}, {7, 8}, {7, 9}, {7, 10}, {8, 9}, {8, 10}, {9, 10}}
In[6]:= connectedpts = Union@Flatten[ordinarylines];
```
Build the ordinary line graph:
```wl
In[7]:= Graph[connectedpts, UndirectedEdge@@@ordinarylines, VertexCoordinates -> v[[connectedpts]]]
Out[7]= Image[...]
```
Identify using ``ToEntity`` :
```wl
In[8]:= ToEntity[%]
Out[8]= Entity["Graph", {"Complete", 10}]
```
</result>
<result url='https://resources.wolframcloud.com/FunctionRepository/resources/TurtleArt#809943932'>
# WFR > TurtleArt > Examples > Neat Examples > Neonsqi
Draw [neonsqi](https://turtleart.org/programming/book1/code.html?6) :
```wl
In[1]:=
Module[{sqi},
sqi[] := Module[{box1 = 0},
ResourceFunction["TurtleArt"]["SetXY"][0, 0];
ResourceFunction["TurtleArt"]["SetHeading"][0];
Do[
ResourceFunction["TurtleArt"]["Forward"][box1];
ResourceFunction["TurtleArt"]["Right"][89];
box1 += 10
,
80
]
];
ResourceFunction["TurtleArt"]["Clean"][];
ResourceFunction["TurtleArt"]["SetPensize"][100];
ResourceFunction["TurtleArt"]["SetColor"][10];
ResourceFunction["TurtleArt"]["SetShade"][100];
Do[
sqi[];
ResourceFunction["TurtleArt"]["SetShade"][ResourceFunction["TurtleArt"]@"Shade" - 8];
ResourceFunction["TurtleArt"]["SetPensize"][ResourceFunction["TurtleArt"]@"Pensize" - 1]
,
100
];
ResourceFunction["TurtleArt"]["Draw"][]
]
Out[1]= !(*GraphicsBox[«7»])
```
</result>
<result url='https://resources.wolframcloud.com/FunctionRepository/resources/DrawSketch#91293614'>
# WFR > DrawSketch > Examples > Neat Examples
Create a function which displays an animation showing the object being drawn from the sequence of pen strokes chosen by the network:
```wl
In[1]:=
animateSketch[obj_] := DynamicModule[{lines, plotRange}, lines = DeleteCases[drawSketch[obj], {}];
plotRange = Map[MinMax, 1.05 * {lines[[All, All, 1]], lines[[All, All, 2]]}];
Animate[Graphics[Line@lines[[1 ;; i]], PlotRange -> plotRange], {i, 1, Length[lines], 1}, AnimationRepetitions -> 1]]
In[2]:= animateSketch["Bird"]
Out[2]= Image[...]
```
</result>",
"code":200,
"success":true,
"uuid":"595b6b47-ea8f-4352-af5b-dfcfcf096c17"
}
Request Parameters
The following parameters can be passed in the body of an API request:
"context"
"count"
5
context (required)
The required parameter "context" specifies the message or messages for which additional prompting is generated. "context" accepts the following forms:
"query"
{
"context" : [
{
"role" : "user",
"content" : "YOUR PROMPT"
},
{
"role" : "assistant"
"content" : "API RESPONSE"
},
{
"role" : "user"
"content" : "YOUR NEXT PROMPT"
}
]
}
curl -X POST https://services.wolfram.com/api/apis/v1/WolframAlphaContext \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "context": "What's the 123456789th prime?" }'
{
"result":"IMPORTANT: The following information was automatically generated using Wolfram Alpha and should be used to help answer the user's query using factual information.
======
<result query='123456789th prime number' url='https://www.wolframalpha.com/input?i=123456789th+prime+number'>
# Input
p_123456789
# Result
2543568463
# Scientific notation
2.543568463 * 10^9
# Number line

# Number name
2 billion 543 million 568 thousand 463
# Number length
10 decimal digits
# Residues modulo small integers

m | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
2543568463 mod m | 1 | 1 | 3 | 3 | 1 | 2 | 7 | 1
# Property
2543568463 is a number that cannot be written as a sum of 3 squares.
2543568463 is the 123456789th prime number.
2543568463 is an odd number.
# Density of primes <= 2543568463
0.0485368
# Comparison
≈ 0.32 × the number of people alive today (≈ 7.8×10^9)
# Series representation
p_123456789 = 2 + sum_(k=2)^floor(2 + 246913578 log(123456789))(1 - floor(π(k)/123456789))
p_123456789 = 1 + sum_(k=1)^(2^123456789)
floor(3^(2/123456789) 13717421^(1/123456789) (1/(1 + π(k)))^(1/123456789))
p_123456789 = sum_(k=0)^15241578750190521 g(1 - g(-123456789 + sum_(j=0)^k r((g(-1
+ j)!)^2, j))) for (g(m) = m θ(m) and δ_(0, b) (a - a mod b) + a mod b = r(a, b))
# Neighboring primes
p_123456788 = 2543568457 | p_123456790 = 2543568479
</result>
======
You can use any Markdown links from these results in your response to show images, formatted expressions, etc. to the user.
If you use any information from these results, you should cite the relevant URL with a Markdown link in your response.",
"code":200,
"success":true,
"uuid":"6b56b1f3-c274-4de4-a142-e5f31991c279"
}
count (optional)
Use the optional "count" parameter to specify an upper bound on the number of related queries to generate. (The default value of "count" is 5.)
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageHints \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "context": "Compare the Eiffel Tower to the pyramids at Giza", "count": 2 }'
Response
The returned JSON contains the following fields:
result(string) A collection of Wolfram Language documentation code samples that typically includes related descriptive text and one or more input-output pairscode(integer) API status code (e.g.200,400,403,501, ...)success(Boolean)trueorfalsedepending on whether the request completed successfullyuuid(string) A unique ID labeling the response
Status Codes
200
This status indicates a success.
HTTP Status400
This status indicates that the API did not find an input parameter while parsing. In most cases, this can be fixed by checking that you have used the correct syntax for including the input parameter.
HTTP Status403
This status is returned when a request contains a missing or invalid API key in the authorization header. Double-check that your AppID is typed correctly and is using the correct syntax.
HTTP Status501
This status is returned if a given input value cannot be interpreted by this API. This is commonly caused by input that is misspelled, poorly formatted or otherwise unintelligible. Because this API is designed to return results for use in LLMs, the body of the 501 message may contain suggested inputs. You may occasionally receive this status when requesting information on topics that are restricted or not covered.
Use of these APIs is subject to the API Terms of Use and Commercial Terms of Use.