There is a common misconception that a “story by” credit may be given to a person who simply has the story idea for a film or television program. This is never the case, as all writing credits are for actual writing. Often, a screenwriter produces a spec script that, after being optioned, undergoes a “page one rewrite” that produces a new draft. In many such cases, the original author receives the “story by” rather than “screenplay by” credit.
The film and tv industry in the USA is extremely unionised and as such there are many rules that screenwriters have to adhere to.
This wikipedia page has an interesting list of rules for members of the Writer’s Guild of America regarding screenwriting accreditation.